我试图了解Cordova WebView-Native
桥的吞吐速度。为此,我将发送一个确定大小的Uint8Array
。但是,我原本预计这座桥的吞吐速度会更高。
在iPhone 4s和Cordova 5.4.1上进行测试,吞吐速度 ~0.8mb / s 。这对我来说很低(基于Cordva应用程序的一些经验,但这当然是主观的)。
问题:这是现实吗?
我认为如果不发布我的代码,这些问题就没有显示足够的信息,因此我附上了我的代码:
我的JavaScript代码:
var success = function(endTime) {
//endTime is unix epoch time (ms)
var time_df = endTime - beginTime
results.push(time_df)
numTests += 1;
sendMessage()
}
var sendMessage = function() {
// execute test 30 times
if (numTests < 30) {
beginTime = +new Date()
bench.send(payload, success, fail)
} else {
console.log('results', results)
}
}
var createPayload = function(size) {
size = size * 1000;
var bufView = new Uint8Array(size);
for (var i = 0; i < size; ++i) {
bufView[i] = i % 20;
}
return bufView.buffer;
}
var startTest = function() {
// create payload of 500kb
payload = createPayload(500)
sendMessage()
}
我的Objective-C代码。 代码基本上做了一件事:在收到有效负载后返回unix纪元时间。
(void)send:(CDVInvokedUrlCommand*)command
{
NSTimeInterval time = ([[NSDate date] timeIntervalSince1970]); // returned as a double
long digits = (long)time; // this is the first 10 digits
int decimalDigits = (int)(fmod(time, 1) * 1000); // this will get the 3 missing digits
long timestamp = (digits * 1000) + decimalDigits;
NSString *timestampString = [NSString stringWithFormat:@"%ld%d",digits ,decimalDigits];
NSString* callbackId = [command callbackId];
CDVPluginResult* result = [CDVPluginResult
resultWithStatus:CDVCommandStatus_OK
messageAsString:timestampString];
[self success:result callbackId:callbackId];
}