为什么PhoneGap似乎比Titanium快? [英] Why does PhoneGap seem faster than Titanium?

查看:143
本文介绍了为什么PhoneGap似乎比Titanium快?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想测量一些跨平台解决方案的执行性能,其中包括:Titanium和PhoneGap。

I'm trying to measure the execution perfomance of a few cross-platform solutions, among which are: Titanium and PhoneGap.

这里有一个Titanium版本的性能测试器,它很简单,但我只是想得到一个感觉,我的代码执行速度有多快:

So here's an example of the Titanium version of my performance tester, it's very simple, but I'm just trying to get a feeling of how fast my code gets executed:

var looplength;
var start1;
var start2;
var end1;
var end2;
var duration1;
var duration2;
var diff;
var diffpiter;
var power;
var info;

for (power = 0; power < 24; power++) {
  looplength = Math.pow(2, power);

  start1 = new Date().getTime();
  for (iterator = 0; iterator < looplength; iterator++) {a=iterator;b=iterator;}
  end1 = new Date().getTime();

  start2 = new Date().getTime();
  for (iterator = 0; iterator < looplength; iterator++) {a=iterator;}
  end2 = new Date().getTime();

  duration1 = end1 - start1;
  duration2 = end2 - start2;
  diff      = duration1 - duration2;
  diffpiter = diff / looplength;

  info={title:'2^' + power + ' ' + diffpiter};
  tableView.appendRow(Ti.UI.createTableViewRow(info),{animated:true});
}

PhoneGap版本是相同的,除了最后两行, / p>

The PhoneGap version is the same except for the last two lines which get replaced

document.write('2^' + power + ' ' + diffpiter + '<br />');

两者都在iPhone 4S上执行。我已经运行了多次测试,以消除错误。

Both are executed on an iPhone 4S. I've run the test numerous times, to eliminate errors.

Titanium版本测量的所有的名称如何〜0.0009 每毫秒迭代一次,而PhoneGap版本每次迭代测量〜0.0002 毫秒?

How in the name of all that is holy can the Titanium version measure ~0.0009 milliseconds per iteration while the PhoneGap version measures ~0.0002 milliseconds per iteration?

应该编译我的javascript代码,所以我期望它更快。在这种情况下,它至少 4倍更慢!我不是性能测试的专家,但我设计的测试应该至少是远程的准确...

Titanium is supposed to compile my javascript code so I expect it to be faster. In this case however it's at least 4 times slower! I'm not an expert on performance testing, but the test I designed should be at least remotely accurate...

感谢您能给我的任何提示。 / p>

Thank you for any tips you can give me.

推荐答案

这是基本的JavaScript,并不是所有的JavaScript都编译为本地代码。基本上当您使用Titanium API时,它将被转换为Objective-C或Java代码。但是为了灵活和动态,有一个JavaScript解释器编译的应用程序,并基本上运行你写的JavaScript。

This is basic JavaScript, and not all JavaScript is compiled to native code. Basically when you use the Titanium API, that will be converted to Objective-C or Java code. But to be flexible and dynamic there is a JavaScript interpreter compiled with the App, and that basically runs the JavaScript you have written.

这使得应用程序更慢。但是纯粹测试这些东西是没有用的。如果你想做一个完整的测试,你需要使用Titanium API,并将其与PhoneGap比较。

This makes the App slower. But testing it purely on these things is useless. If you want to do a full suit of testing you need to use the Titanium API too, and compare that to the PhoneGap one.

你会注意到,Phonegap没有编译为本地代码,它会感觉不同,视觉上Titanium会更快。

What you'll notice, as Phonegap does not compile to native code, it will feel different, and visually Titanium will behave faster.

这篇关于为什么PhoneGap似乎比Titanium快?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆