java 类似xamarin_有人有基准(代码和结果)比较在Xamarin C#和Java编写的Android应用程序的性能吗?...
我遇到了Xamarin聲稱他們在Android上的Mono實現(xiàn)和他們的C#編譯的應(yīng)用程序比Java代碼更快。有沒有人在不同的Android平臺上執(zhí)行非常類似的Java和C#代碼的實際基準(zhǔn)來驗證此類聲明,可以發(fā)布代碼和結(jié)果?
于2013年6月18日添加
因為沒有答案,沒有人能找到這樣的基準(zhǔn),決定做我自己的測試。不幸的是,我的問題仍然是“鎖定”,所以我不能發(fā)布這個答案,只有編輯的問題。請投票重新開啟此問題。對于C#,我使用Xamarin.Android ver。 4.7.09001(beta)。源代碼,我用于測試的所有數(shù)據(jù)和編譯的APK包都在GitHub上:
如果有人想在其他設(shè)備或仿真器上重復(fù)我的測試,我也有興趣了解結(jié)果。
我的測試結(jié)果
我將我的句子提取器類移植到C#(從我的@Voice Aloud Reader應(yīng)用程序),并對英語,俄語,法語,波蘭語和捷克語的10個html文件運行一些測試。每次運行在所有10個文件上執(zhí)行5次,并且3個不同的設(shè)備和一個模擬器的總時間在下面發(fā)布。我測試了“發(fā)布”構(gòu)建,而不啟用調(diào)試。
HTC Nexus One Android 2.3.7(API 10) – CyanogenMod ROM
Java:總計總時間(5次運行):12361 ms,文件讀取總計:13304 ms
C#:總計總時間(5次運行):17504 ms,文件讀取總計:17956 ms
三星Galaxy S2 SGH-I777(Android 4.0.4,API 15) – CyanogenMod ROM
Java:總計總時間(5次運行):8947毫秒,文件讀取總計:9186毫秒
C#:總計總時間(5次運行):9884 ms,文件讀取總計:10247 ms
三星GT-N7100(Android 4.1.1 JellyBean,API 16) – 三星ROM
Java:總計總時間(5次運行):9742 ms,文件讀取總計:10111 ms
C#:總計總時間(5次運行):10459 ms,文件讀取總計:10696 ms
模擬器 – 英特爾(Android 4.2,API 17)
Java:總計總時間(5次運行):2699毫秒,文件讀取總計:3127毫秒
C#:總計總時間(5次運行):2049 ms,文件讀取總計:2182 ms
模擬器 – 英特爾(Android 2.3.7,API 10)
Java:總計總時間(5次運行):2992 ms,文件讀取總計:3591 ms
C#:總計總時間(5次運行):2049 ms,文件讀取總計:2257 ms
模擬器 – 臂(Android 4.0.4,API 15)
Java:總計總時間(5次運行):41751 ms,文件讀取總計:43866 ms
C#:總計總時間(5次運行):44136 ms,文件讀取總計:45109 ms
簡要討論
我的測試代碼主要包含文本解析,替換和正則表達式搜索,也許對于其他代碼(例如更多的數(shù)值操作),結(jié)果會不同。在所有具有ARM處理器的設(shè)備上,Java的性能都優(yōu)于Xamarin C#代碼。最大的區(qū)別是在Android 2.3,其中C#代碼運行在約。 70%的Java速度。
在Intel模擬器(使用Intel HAX技術(shù),仿真器以快速virt模式運行)中,Xamarin C#代碼運行我的示例代碼比Java快得多 – 大約1.35倍的時間。也許Mono虛擬機代碼和庫在英特爾比在ARM上更好的優(yōu)化?
編輯2013年7月8日
我剛剛安裝了Genymotion Android模擬器,它運行在Oracle VirtualBox,再次這個使用本機英特爾處理器,而不是模擬ARM處理器。和英特爾HAX模擬器一樣,C#的運行速度也快得多。這里是我的結(jié)果:
Genymotion模擬器 – Intel(Android 4.1.1,API 16)
Java:
Grand total time (5 runs): 2069 ms, with file reading total: 2248 ms
C#:
Grand total time (5 runs): 1543 ms, with file reading total: 1642 ms
然后我注意到,有一個更新的Xamarin.Android beta版本4.7.11,發(fā)行說明提到一些變化在Mono運行時以及。決定快速測試一些ARM設(shè)備,大驚喜 – C#數(shù)字改進:
BN Nook XD,ARM(Android 4.0)
Java: Grand total time (5 runs): 8103 ms, with file reading total: 8569 ms
C#: Grand total time (5 runs): 7951 ms, with file reading total: 8161 ms
哇! C#現(xiàn)在比Java好?決定重復(fù)測試我的Galaxy Note 2:
三星Galaxy Note 2 – ARM(Android 4.1.1)
Java: Grand total time (5 runs): 9675 ms, with file reading total: 10028 ms
C#: Grand total time (5 runs): 9911 ms, with file reading total: 10104 ms
這里的C#似乎只是稍慢,但這些數(shù)字給我一個暫停:為什么時間比Nook HD長,即使Note 2有一個更快的處理器?答案:省電模式。在Nook,它被禁用,注2 – 啟用。決定在禁用省電模式的情況下進行測試(與啟用一樣,也會限制處理器速度):
三星Galaxy Note 2 – ARM(Android 4.1.1),省電省電
Java: Grand total time (5 runs): 7153 ms, with file reading total: 7459 ms
C#: Grand total time (5 runs): 6906 ms, with file reading total: 7070 ms
現(xiàn)在,令人驚訝的是,C#在ARM處理器上也比Java快一點。大改善!
修改2013年7月12日
我們都知道,沒有什么比本機代碼的速度,我不滿意我的句子拆分器在Java或C#的性能,特別是我需要改進它(從而使它更慢)。決定重寫它在C。這里是一個小(即一組較小的文件比以前的測試,由于其他原因)比較本機的速度與Java在我的Galaxy Note 2,禁用省電模式:
Java:
總計時間(5次運行):3292 ms,文件讀取總計:3454 ms
本機拇指:
總計時間(5次運行):537 ms,文件讀取總計:657 ms
本機臂:
總計時間(5次運行):458 ms,文件讀取總計:587 ms
看起來像我的特定測試,本機代碼是Java的6到7倍。注意:不能在Android上使用std :: regex類,所以不得不編寫我自己的專門例程搜索段落或html標(biāo)簽。我使用regex在PC上對同一代碼進行初始測試,比Java快4到5倍。
!!再次使用char *或wchar *指針喚醒原始內(nèi)存,我立即感到20歲了! 🙂
修改2013年7月15日
(請參閱下面,與編輯7/30/2013,使用Dot42更好的結(jié)果)
有一些困難我管理我的C#測試到Dot42(版本1.0.1.71測試版),另一個C#平臺Android。初步結(jié)果顯示,在Intel Android模擬器上,Dot42代碼比Xamarin C#(v。4.7.11)慢約3倍(3倍)。一個問題是,Dot42中的System.Text.RegularExpressions類沒有我在Xamarin測試中使用的Split()函數(shù),所以我使用Java.Util.Regex類,而Java.Util.Regex.Pattern.Split ),所以在這個特殊的地方在代碼中有這個小的區(qū)別。不應(yīng)該是一個大問題。 Dot42編譯為Dalvik(DEX)代碼,因此它在Android上與Java本地協(xié)作,不需要從C#到XAMarin的昂貴的互操作。
為了比較,我還在ARM設(shè)備上運行測試 – 這里Dot42代碼是“只”比Xamarin C#慢兩倍。這里是我的結(jié)果:
HTC Nexus One Android 2.3.7(ARM)
Java: Grand total time (5 runs): 12187 ms, with file reading total: 13200 ms
Xamarin C#: Grand total time (5 runs): 13935 ms, with file reading total: 14465 ms
Dot42 C#: Grand total time (5 runs): 26000 ms, with file reading total: 27168 ms
三星Galaxy Note 2,Android 4.1.1(ARM)
Java: Grand total time (5 runs): 6895 ms, with file reading total: 7275 ms
Xamarin C#: Grand total time (5 runs): 6466 ms, with file reading total: 6720 ms
Dot42 C#: Grand total time (5 runs): 11185 ms, with file reading total: 11843 ms
英特爾仿真器,Android 4.2(x86)
Java: Grand total time (5 runs): 2389 ms, with file reading total: 2770 ms
Xamarin C#: Grand total time (5 runs): 1748 ms, with file reading total: 1933 ms
Dot42 C#: Grand total time (5 runs): 5150 ms, with file reading total: 5459 ms
對我來說,還有趣的是,Xamarin C#在較新的ARM設(shè)備上比Java快一點,在舊的Nexus One上稍慢。如果任何人也想運行這些測試,請讓我知道,我會更新GitHub上的源。這將是特別有趣的看到從一個真正的Android設(shè)備與英特爾處理器的結(jié)果。
更新7/26/2013
只是一個快速更新,重新編譯的基準(zhǔn)測試應(yīng)用程序與最新的Xamarin.Android 4.8,以及dot42 1.0.1.72更新發(fā)布今天 – 沒有重大變化從以前報告的結(jié)果。
更新7/30/2013 – 更好的結(jié)果dot42
重新測試Dot42與我的Java代碼的羅伯特(從dot42制造商)端口到C#。在我最初為Xamarin做的C#端口中,我替換了一些原生的Java類,如ListArray,用C#本地的List類,等等。Robert沒有我的Dot42源代碼,所以他再次從Java移植并使用原始的Java類這樣的地方,這有利于Dot42,我想,因為它運行在Dalvik VM,像Java,而不是在Mono,像Xamarin。現(xiàn)在Dot42的結(jié)果好多了。這是我的測試日志:
7/30/2013 – Dot42 tests with more Java classes in Dot42 C#
Intel emulator, Android 4.2
Dot42, Greg’s Code using StringBuilder.Replace() (as in Xamarin):
Grand total time (5 runs): 3646 ms, with file reading total: 3830 ms
Dot42, Greg’s Code using String.Replace() (as in Java and Robert’s code):
Grand total time (5 runs): 3027 ms, with file reading total: 3206 ms
Dot42, Robert’s Code:
Grand total time (5 runs): 1781 ms, with file reading total: 1999 ms
Xamarin:
Grand total time (5 runs): 1373 ms, with file reading total: 1505 ms
Java:
Grand total time (5 runs): 1841 ms, with file reading total: 2044 ms
ARM, Samsung Galaxy Note 2, power saving off, Android 4.1.1
Dot42, Greg’s Code using StringBuilder.Replace() (as in Xamarin):
Grand total time (5 runs): 10875 ms, with file reading total: 11280 ms
Dot42, Greg’s Code using String.Replace() (as in Java and Robert’s code):
Grand total time (5 runs): 9710 ms, with file reading total: 10097 ms
Dot42, Robert’s Code:
Grand total time (5 runs): 6279 ms, with file reading total: 6622 ms
Xamarin:
Grand total time (5 runs): 6201 ms, with file reading total: 6476 ms
Java:
Grand total time (5 runs): 7141 ms, with file reading total: 7479 ms
我仍然認(rèn)為Dot42還有很長的路要走。擁有類Java類(例如ArrayList)和良好的性能,將使從Java到C#的移植代碼更容易。然而,這是我不可能做很多事情。我寧愿想使用現(xiàn)有的C#代碼(庫等),這將使用本機C#類(例如List),并將執(zhí)行緩慢與當(dāng)前dot42代碼,非常好與Xamarin。
格雷格
總結(jié)
以上是生活随笔為你收集整理的java 类似xamarin_有人有基准(代码和结果)比较在Xamarin C#和Java编写的Android应用程序的性能吗?...的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 玩家才是微软收购案最大的赢家
- 下一篇: c# char unsigned_dll