Spads 出品,作者 WangXP 与 Shane
目录 ---------- ---------- ---------- ---------- 1 【综述】 2 【程序】 3 【功能】 4 【性能】 测试程序 _ 测试分析 5 【附录】 因为篇幅原因,51CTO 只允许单篇 80000 个字符,所以本文将拆分成几个部分发布。 其中 5【附录】是针对 1【综述】内容的,所以放在了一起。 4 【性能】 ---------- ---------- ---------- ---------- 依照之前提到的性能测试方法,每种方法循环量 loopNum 设为 12001000 ,各种情况性能表现如下。- Performance test...
- Loop times = 1200 1000
- ---------- ---------- ---------- ----------
- String: 15
- tool:1201ms. --:1810ms. ap:2014ms. lib:3058ms. reg:5508ms.
- tool:982ms. --:1577ms. ap:1780ms. lib:2746ms. reg:5166ms.
- tool:967ms. --:1577ms. ap:1812ms. lib:2810ms. reg:5136ms.
- tool:983ms. --:1498ms. ap:1779ms. lib:2590ms. reg:5009ms.
- tool:920ms. --:1452ms. ap:1701ms. lib:2590ms. reg:5118ms.
- tool:998ms. --:1514ms. ap:1795ms. lib:2668ms. reg:5165ms.
- tool:998ms. --:1545ms. ap:1764ms. lib:2700ms. reg:5088ms.
- StringTool: 7049 ms.
- Direct: 10973 ms.
- WholeApacheUtils: 12645 ms.
- JavaLib: 19162 ms.
- WholeRegex: 36190 ms.
- ---------- ---------- ---------- ----------
- String: 28
- tool:1154ms. --:1654ms. ap:1966ms. lib:2684ms. reg:5353ms.
- tool:1123ms. --:1670ms. ap:1889ms. lib:2762ms. reg:5259ms.
- tool:1139ms. --:1764ms. ap:1889ms. lib:2747ms. reg:5460ms.
- tool:1168ms. --:1715ms. ap:1996ms. lib:2776ms. reg:5413ms.
- tool:1092ms. --:1842ms. ap:1842ms. lib:2794ms. reg:5447ms.
- tool:1170ms. --:1655ms. ap:1998ms. lib:2793ms. reg:5415ms.
- tool:1170ms. --:1671ms. ap:1858ms. lib:2685ms. reg:5338ms.
- StringTool: 8016 ms.
- Direct: 11971 ms.
- WholeApacheUtils: 13438 ms.
- JavaLib: 19241 ms.
- WholeRegex: 37685 ms.
- ---------- ---------- ---------- ----------
- String: 3.8
- tool:2121ms. --:2793ms. ap:3885ms. lib:4775ms. reg:7942ms.
- tool:2075ms. --:2778ms. ap:3808ms. lib:4760ms. reg:7724ms.
- tool:2137ms. --:2840ms. ap:4135ms. lib:5230ms. reg:8803ms.
- tool:2044ms. --:2606ms. ap:3480ms. lib:4713ms. reg:7959ms.
- tool:2013ms. --:2451ms. ap:3620ms. lib:4760ms. reg:8193ms.
- tool:1856ms. --:2777ms. ap:4150ms. lib:5009ms. reg:8223ms.
- tool:1872ms. --:2403ms. ap:3729ms. lib:4887ms. reg:8382ms.
- StringTool: 14118 ms.
- Direct: 18648 ms.
- WholeApacheUtils: 26807 ms.
- JavaLib: 34134 ms.
- WholeRegex: 57226 ms.
- ---------- ---------- ---------- ----------
- String: -99
- tool:1186ms. --:1780ms. ap:2248ms. lib:3325ms. reg:6649ms.
- tool:1108ms. --:1826ms. ap:2107ms. lib:2981ms. reg:6102ms.
- tool:1139ms. --:1717ms. ap:2170ms. lib:3247ms. reg:6446ms.
- tool:1154ms. --:1701ms. ap:1998ms. lib:3074ms. reg:6039ms.
- tool:1139ms. --:1686ms. ap:2029ms. lib:3199ms. reg:6508ms.
- tool:1123ms. --:1655ms. ap:1920ms. lib:2902ms. reg:5914ms.
- tool:1154ms. --:1748ms. ap:2123ms. lib:3215ms. reg:6773ms.
- StringTool: 8003 ms.
- Direct: 12113 ms.
- WholeApacheUtils: 14595 ms.
- JavaLib: 21943 ms.
- WholeRegex: 44431 ms.
- ---------- ---------- ---------- ----------
- String: .45
- tool:1763ms. --:2435ms. ap:3777ms. lib:4651ms. reg:7662ms.
- tool:1888ms. --:2263ms. ap:3823ms. lib:4963ms. reg:8131ms.
- tool:2153ms. --:2965ms. ap:4182ms. lib:5321ms. reg:8271ms.
- tool:1903ms. --:2513ms. ap:3667ms. lib:4713ms. reg:8130ms.
- tool:2075ms. --:2684ms. ap:3948ms. lib:5041ms. reg:8396ms.
- tool:2231ms. --:2809ms. ap:3995ms. lib:5041ms. reg:8208ms.
- tool:2230ms. --:3183ms. ap:4197ms. lib:5306ms. reg:8193ms.
- StringTool: 14243 ms.
- Direct: 18852 ms.
- WholeApacheUtils: 27589 ms.
- JavaLib: 35036 ms.
- WholeRegex: 56991 ms.
- ---------- ---------- ---------- ----------
- String: -.1
- tool:1825ms. --:2434ms. ap:4088ms. lib:4963ms. reg:7661ms.
- tool:2481ms. --:3028ms. ap:4525ms. lib:5665ms. reg:8084ms.
- tool:2153ms. --:2529ms. ap:4338ms. lib:5072ms. reg:7131ms.
- tool:2308ms. --:3292ms. ap:4322ms. lib:5446ms. reg:8224ms.
- tool:2543ms. --:2918ms. ap:4385ms. lib:5415ms. reg:8209ms.
- tool:2418ms. --:3012ms. ap:4213ms. lib:5446ms. reg:7959ms.
- tool:2247ms. --:2700ms. ap:3745ms. lib:4823ms. reg:7554ms.
- StringTool: 15975 ms.
- Direct: 19913 ms.
- WholeApacheUtils: 29616 ms.
- JavaLib: 36830 ms.
- WholeRegex: 54822 ms.
- ---------- ---------- ---------- ----------
- String: null
- --:47ms. tool:125ms. lib:140ms. reg:156ms. ap:156ms.
- --:31ms. lib:94ms. tool:94ms. ap:78ms. reg:125ms.
- --:16ms. ap:95ms. tool:95ms. reg:126ms. lib:126ms.
- --:31ms. lib:94ms. tool:94ms. ap:94ms. reg:109ms.
- --:47ms. reg:94ms. lib:94ms. tool:94ms. ap:94ms.
- --:47ms. lib:94ms. reg:110ms. ap:63ms. tool:125ms.
- --:15ms. reg:78ms. tool:78ms. lib:110ms. ap:110ms.
- Direct: 234 ms.
- WholeApacheUtils: 690 ms.
- StringTool: 705 ms.
- JavaLib: 752 ms.
- WholeRegex: 798 ms.
- ---------- ---------- ---------- ----------
- String: 0x3AFF0
- tool:406ms. ap:579ms. lib:1608ms. reg:4760ms. --:18146ms.
- tool:359ms. ap:578ms. lib:1763ms. reg:5180ms. --:17146ms.
- tool:328ms. ap:530ms. lib:1685ms. reg:4775ms. --:17303ms.
- tool:390ms. ap:562ms. lib:1607ms. reg:5009ms. --:15977ms.
- tool:359ms. ap:546ms. lib:1700ms. reg:4728ms. --:18519ms.
- tool:437ms. ap:702ms. lib:2107ms. reg:5494ms. --:16086ms.
- tool:374ms. ap:515ms. lib:1653ms. reg:5055ms. --:17224ms.
- StringTool: 2653 ms.
- WholeApacheUtils: 4012 ms.
- JavaLib: 12123 ms.
- WholeRegex: 35001 ms.
- Direct: 120401 ms.
- ---------- ---------- ---------- ----------
- String: 042
- tool:1170ms. --:1795ms. ap:2014ms. lib:2934ms. reg:7100ms.
- tool:1482ms. --:2154ms. ap:2481ms. lib:3559ms. reg:7788ms.
- tool:1373ms. --:2029ms. ap:2154ms. lib:3261ms. reg:7381ms.
- tool:1279ms. --:1935ms. ap:2201ms. lib:3339ms. reg:7459ms.
- tool:1279ms. --:1936ms. ap:2294ms. lib:3450ms. reg:7507ms.
- tool:1373ms. --:1826ms. ap:2122ms. lib:3402ms. reg:7583ms.
- tool:1513ms. --:2356ms. ap:2529ms. lib:3668ms. reg:7912ms.
- StringTool: 9469 ms.
- Direct: 14031 ms.
- WholeApacheUtils: 15795 ms.
- JavaLib: 23613 ms.
- WholeRegex: 52730 ms.
- ---------- ---------- ---------- ----------
- String: Spads
- tool:374ms. ap:577ms. lib:1825ms. reg:3480ms. --:15945ms.
- tool:281ms. ap:405ms. lib:1545ms. reg:3090ms. --:15930ms.
- tool:343ms. ap:655ms. lib:1716ms. reg:3324ms. --:16023ms.
- tool:265ms. ap:546ms. lib:1450ms. reg:3136ms. --:16148ms.
- tool:296ms. ap:452ms. lib:1482ms. reg:3012ms. --:18254ms.
- tool:297ms. ap:468ms. lib:1514ms. reg:2903ms. --:17131ms.
- tool:297ms. ap:484ms. lib:1482ms. reg:2981ms. --:15072ms.
- StringTool: 2153 ms.
- WholeApacheUtils: 3587 ms.
- JavaLib: 11014 ms.
- WholeRegex: 21926 ms.
- Direct: 114503 ms.
- ---------- ---------- ---------- ----------
- String:
- tool:93ms. lib:125ms. ap:110ms. reg:2231ms. --:16334ms.
- tool:125ms. lib:156ms. ap:140ms. reg:2683ms. --:15539ms.
- tool:156ms. lib:172ms. ap:156ms. reg:2746ms. --:15570ms.
- tool:125ms. ap:140ms. lib:172ms. reg:2418ms. --:16272ms.
- tool:125ms. lib:125ms. ap:141ms. reg:2153ms. --:14431ms.
- lib:140ms. tool:140ms. ap:125ms. reg:2589ms. --:18627ms.
- tool:141ms. ap:156ms. lib:172ms. reg:2777ms. --:17909ms.
- StringTool: 905 ms.
- WholeApacheUtils: 968 ms.
- JavaLib: 1062 ms.
- WholeRegex: 17597 ms.
- Direct: 114682 ms.
- ---------- ---------- ---------- ----------
- String:
- lib:405ms. tool:421ms. ap:406ms. reg:2854ms. --:18175ms.
- tool:452ms. ap:468ms. lib:530ms. reg:3182ms. --:18833ms.
- lib:499ms. tool:499ms. ap:530ms. reg:2964ms. --:15086ms.
- lib:406ms. tool:421ms. ap:405ms. reg:2683ms. --:17005ms.
- ap:375ms. tool:421ms. lib:453ms. reg:3089ms. --:18752ms.
- tool:514ms. lib:500ms. ap:546ms. reg:3151ms. --:17254ms.
- lib:484ms. tool:484ms. ap:546ms. reg:3183ms. --:14962ms.
- StringTool: 3212 ms.
- WholeApacheUtils: 3276 ms.
- JavaLib: 3277 ms.
- WholeRegex: 21106 ms.
- Direct: 120067 ms.
- ---------- ---------- ---------- ----------
- String: 5 - 3
- tool:530ms. ap:905ms. lib:1904ms. reg:8487ms. --:17490ms.
- tool:484ms. ap:733ms. lib:1483ms. reg:7583ms. --:18051ms.
- tool:514ms. ap:686ms. lib:1467ms. reg:7707ms. --:18285ms.
- tool:640ms. ap:905ms. lib:1904ms. reg:8519ms. --:17474ms.
- tool:437ms. ap:702ms. lib:1546ms. reg:7942ms. --:16881ms.
- tool:453ms. ap:702ms. lib:1546ms. reg:8332ms. --:18941ms.
- tool:593ms. ap:749ms. lib:1857ms. reg:8582ms. --:17335ms.
- StringTool: 3651 ms.
- WholeApacheUtils: 5382 ms.
- JavaLib: 11707 ms.
- WholeRegex: 57152 ms.
- Direct: 124457 ms.
- ---------- ---------- ---------- ----------
- String: 三十八
- tool:328ms. ap:655ms. lib:1857ms. reg:3449ms. --:17537ms.
- tool:265ms. ap:483ms. lib:1466ms. reg:2731ms. --:18020ms.
- tool:265ms. ap:593ms. lib:1685ms. reg:3230ms. --:16101ms.
- tool:265ms. ap:468ms. lib:1420ms. reg:2981ms. --:17287ms.
- tool:328ms. ap:546ms. lib:1591ms. reg:3137ms. --:17318ms.
- tool:390ms. ap:624ms. lib:1685ms. reg:3012ms. --:17568ms.
- tool:265ms. ap:515ms. lib:1513ms. reg:2996ms. --:18005ms.
- StringTool: 2106 ms.
- WholeApacheUtils: 3884 ms.
- JavaLib: 11217 ms.
- WholeRegex: 21536 ms.
- Direct: 121836 ms.
- ---------- ---------- ---------- ----------
- String: 3.1415926.5358
- tool:1248ms. ap:1951ms. lib:3558ms. --:21202ms. reg:46397ms.
- tool:1092ms. ap:1873ms. lib:3245ms. --:20578ms. reg:44931ms.
- tool:1310ms. ap:2247ms. lib:3963ms. --:22497ms. reg:46475ms.
- tool:1154ms. ap:2013ms. lib:3791ms. --:21280ms. reg:46428ms.
- tool:1186ms. ap:1951ms. lib:3371ms. --:22139ms. reg:49457ms.
- tool:1404ms. ap:2310ms. lib:3776ms. --:21233ms. reg:46881ms.
- tool:1108ms. ap:1889ms. lib:3277ms. --:20968ms. reg:43433ms.
- StringTool: 8502 ms.
- WholeApacheUtils: 14234 ms.
- JavaLib: 24981 ms.
- Direct: 149897 ms.
- WholeRegex: 324002 ms.
- ---------- ---------- ---------- ----------
- String: 39501.50
- tool:3744ms. --:4088ms. ap:5929ms. lib:7318ms. reg:15728ms.
- tool:3728ms. --:4353ms. ap:5835ms. lib:7240ms. reg:14511ms.
- tool:3292ms. --:4104ms. ap:5914ms. lib:7225ms. reg:15166ms.
- tool:3198ms. --:3994ms. ap:5773ms. lib:6991ms. reg:15775ms.
- tool:3417ms. --:3698ms. ap:5633ms. lib:7038ms. reg:15198ms.
- tool:3260ms. --:4151ms. ap:6132ms. lib:7474ms. reg:15993ms.
- tool:3214ms. --:3620ms. ap:5399ms. lib:6788ms. reg:15603ms.
- StringTool: 23853 ms.
- Direct: 28008 ms.
- WholeApacheUtils: 40615 ms.
- JavaLib: 50074 ms.
- WholeRegex: 107974 ms.
- ---------- ---------- ---------- ----------
- String: 0.000385427
- tool:4228ms. --:4603ms. ap:6444ms. lib:8177ms. reg:17944ms.
- tool:4087ms. --:4431ms. ap:6678ms. lib:8301ms. reg:17834ms.
- tool:3775ms. --:4306ms. ap:6241ms. lib:7849ms. reg:18801ms.
- tool:3994ms. --:4307ms. ap:6709ms. lib:7771ms. reg:19269ms.
- tool:3526ms. --:4307ms. ap:6053ms. lib:7693ms. reg:18177ms.
- tool:3884ms. --:4073ms. ap:6381ms. lib:7880ms. reg:19269ms.
- tool:3447ms. --:3760ms. ap:5711ms. lib:7225ms. reg:17959ms.
- StringTool: 26941 ms.
- Direct: 29787 ms.
- WholeApacheUtils: 44217 ms.
- JavaLib: 54896 ms.
- WholeRegex: 129253 ms.
- ---------- ---------- ---------- ----------
- String: .33796678
- tool:3525ms. --:3916ms. ap:5648ms. lib:6928ms. reg:15712ms.
- tool:3292ms. --:3745ms. ap:5711ms. lib:7178ms. reg:15556ms.
- tool:3775ms. --:4119ms. ap:6007ms. lib:7287ms. reg:16071ms.
- tool:3463ms. --:3823ms. ap:5601ms. lib:7069ms. reg:14246ms.
- tool:3401ms. --:4026ms. ap:5991ms. lib:7162ms. reg:15884ms.
- tool:3806ms. --:4291ms. ap:5898ms. lib:7396ms. reg:15915ms.
- tool:3884ms. --:4088ms. ap:5960ms. lib:7553ms. reg:15946ms.
- StringTool: 25146 ms.
- Direct: 28008 ms.
- WholeApacheUtils: 40816 ms.
- JavaLib: 50573 ms.
- WholeRegex: 109330 ms.
- ---------- ---------- ---------- ----------
- String: 300011110000
- tool:3213ms. --:4322ms. ap:4869ms. lib:6522ms. reg:16897ms.
- tool:3354ms. --:4010ms. ap:4899ms. lib:6647ms. reg:18614ms.
- tool:3260ms. --:3792ms. ap:4463ms. lib:6117ms. reg:17178ms.
- tool:3276ms. --:3776ms. ap:4696ms. lib:6444ms. reg:17678ms.
- tool:3057ms. --:3838ms. ap:4853ms. lib:6382ms. reg:17351ms.
- tool:3448ms. --:4197ms. ap:5040ms. lib:6492ms. reg:18489ms.
- tool:3588ms. --:4322ms. ap:5727ms. lib:7880ms. reg:20377ms.
- StringTool: 23196 ms.
- Direct: 28257 ms.
- WholeApacheUtils: 34547 ms.
- JavaLib: 46484 ms.
- WholeRegex: 126584 ms.
- ---------- ---------- ---------- ----------
- String: 300 1500 1010
- tool:3432ms. --:3855ms. ap:5134ms. lib:6476ms. reg:18739ms.
- tool:3604ms. --:3963ms. ap:5055ms. lib:6367ms. reg:19409ms.
- tool:3432ms. --:3526ms. ap:4822ms. lib:5945ms. reg:18754ms.
- tool:2683ms. --:3371ms. ap:4712ms. lib:6258ms. reg:18239ms.
- tool:3198ms. --:3604ms. ap:4900ms. lib:6132ms. reg:19472ms.
- tool:3213ms. --:3620ms. ap:4790ms. lib:6133ms. reg:17444ms.
- tool:3135ms. --:3823ms. ap:5367ms. lib:6679ms. reg:18941ms.
- StringTool: 22697 ms.
- Direct: 25762 ms.
- WholeApacheUtils: 34780 ms.
- JavaLib: 43990 ms.
- WholeRegex: 130998 ms.
- ---------- ---------- ---------- ----------
- String: -570 0015 6726
- tool:3323ms. --:3527ms. ap:5290ms. lib:6508ms. reg:18911ms.
- --:3588ms. tool:3667ms. ap:5273ms. lib:6554ms. reg:18224ms.
- tool:3588ms. --:4072ms. ap:5071ms. lib:6616ms. reg:18926ms.
- tool:3697ms. --:3948ms. ap:5196ms. lib:6304ms. reg:18910ms.
- tool:3698ms. --:4135ms. ap:5086ms. lib:6632ms. reg:17382ms.
- tool:3760ms. --:3932ms. ap:5445ms. lib:6726ms. reg:19612ms.
- tool:3448ms. --:3776ms. ap:5103ms. lib:6227ms. reg:18365ms.
- StringTool: 25181 ms.
- Direct: 26978 ms.
- WholeApacheUtils: 36464 ms.
- JavaLib: 45567 ms.
- WholeRegex: 130330 ms.
- ---------- ---------- ---------- ----------
- String: -2378957832975
- tool:3354ms. --:4041ms. ap:5243ms. lib:6897ms. reg:18660ms.
- tool:3338ms. --:3886ms. ap:5086ms. lib:7068ms. reg:19347ms.
- tool:3978ms. --:3962ms. ap:5414ms. lib:7006ms. reg:18848ms.
- tool:3884ms. --:4525ms. ap:5352ms. lib:6928ms. reg:18551ms.
- tool:3962ms. --:4525ms. ap:5508ms. lib:6959ms. reg:19159ms.
- tool:4196ms. --:4306ms. ap:5164ms. lib:7161ms. reg:19018ms.
- tool:3931ms. --:3979ms. ap:5118ms. lib:6913ms. reg:17943ms.
- StringTool: 26643 ms.
- Direct: 29224 ms.
- WholeApacheUtils: 36885 ms.
- JavaLib: 48932 ms.
- WholeRegex: 131526 ms.
- ---------- ---------- ---------- ----------
- String: 1370 0000
- tool:2262ms. --:2825ms. ap:3621ms. lib:5041ms. reg:13778ms.
- tool:2559ms. --:3184ms. ap:4010ms. lib:5213ms. reg:15432ms.
- tool:2434ms. --:3199ms. ap:4057ms. lib:5259ms. reg:14028ms.
- tool:2153ms. --:2778ms. ap:3964ms. lib:5228ms. reg:13778ms.
- tool:2480ms. --:2965ms. ap:3979ms. lib:4947ms. reg:15009ms.
- tool:2309ms. --:2918ms. ap:3761ms. lib:4916ms. reg:13872ms.
- tool:2465ms. --:2965ms. ap:3714ms. lib:5041ms. reg:14760ms.
- StringTool: 16662 ms.
- Direct: 20834 ms.
- WholeApacheUtils: 27106 ms.
- JavaLib: 35645 ms.
- WholeRegex: 100657 ms.
- ---------- ---------- ---------- ----------
- String: 2015773
- tool:1872ms. --:2341ms. ap:3012ms. lib:4463ms. reg:11422ms.
- tool:2387ms. --:3449ms. ap:3466ms. lib:4854ms. reg:11641ms.
- tool:1919ms. --:2840ms. ap:3121ms. lib:4401ms. reg:12264ms.
- tool:1685ms. --:2325ms. ap:2934ms. lib:4635ms. reg:12030ms.
- tool:2012ms. --:2497ms. ap:3214ms. lib:4666ms. reg:11172ms.
- tool:2184ms. --:3043ms. ap:3495ms. lib:4854ms. reg:12780ms.
- tool:2496ms. --:3152ms. ap:3667ms. lib:4932ms. reg:13076ms.
- StringTool: 14555 ms.
- Direct: 19647 ms.
- WholeApacheUtils: 22909 ms.
- JavaLib: 32805 ms.
- WholeRegex: 84385 ms.
- ---------- ---------- ---------- ----------
- String: 3850
- tool:1778ms. --:2653ms. ap:3137ms. lib:4401ms. reg:9878ms.
- tool:1669ms. --:2466ms. ap:2824ms. lib:4105ms. reg:8739ms.
- tool:1326ms. --:2107ms. ap:2513ms. lib:3621ms. reg:8817ms.
- tool:1794ms. --:2501ms. ap:2844ms. lib:4000ms. reg:8603ms.
- tool:1326ms. --:1904ms. ap:2326ms. lib:3527ms. reg:8957ms.
- tool:1731ms. --:2342ms. ap:2810ms. lib:4059ms. reg:9116ms.
- tool:1623ms. --:2560ms. ap:2746ms. lib:3840ms. reg:9364ms.
- StringTool: 11247 ms.
- Direct: 16533 ms.
- WholeApacheUtils: 19200 ms.
- JavaLib: 27553 ms.
- WholeRegex: 63474 ms.
- ---------- ---------- ---------- ----------
- String: -80058
- tool:2199ms. --:2871ms. ap:3370ms. lib:4510ms. reg:9768ms.
- tool:1809ms. --:2232ms. ap:2809ms. lib:4337ms. reg:10516ms.
- tool:2200ms. --:2669ms. ap:3371ms. lib:4433ms. reg:10611ms.
- tool:1779ms. --:2326ms. ap:2684ms. lib:3761ms. reg:9643ms.
- tool:2106ms. --:2809ms. ap:3370ms. lib:4729ms. reg:10424ms.
- tool:1654ms. --:2326ms. ap:3215ms. lib:4651ms. reg:10362ms.
- tool:1716ms. --:1966ms. ap:2762ms. lib:4261ms. reg:10393ms.
- StringTool: 13463 ms.
- Direct: 17199 ms.
- WholeApacheUtils: 21581 ms.
- JavaLib: 30682 ms.
- WholeRegex: 71717 ms.
- ---------- ---------- ---------- ----------
- String: -1 2853 2781
- tool:3073ms. --:3370ms. ap:4525ms. lib:5633ms. reg:17475ms.
- tool:2558ms. --:3027ms. ap:4634ms. lib:5556ms. reg:16101ms.
- tool:3292ms. --:3590ms. ap:4478ms. lib:5915ms. reg:16009ms.
- tool:2762ms. --:2918ms. ap:4728ms. lib:5821ms. reg:16727ms.
- tool:2730ms. --:2996ms. ap:4650ms. lib:5758ms. reg:16102ms.
- tool:2949ms. --:3386ms. ap:4354ms. lib:5743ms. reg:15447ms.
- tool:2762ms. --:3792ms. ap:5634ms. lib:6743ms. reg:16696ms.
- StringTool: 20126 ms.
- Direct: 23079 ms.
- WholeApacheUtils: 33003 ms.
- JavaLib: 41169 ms.
- WholeRegex: 114557 ms.
- ---------- ---------- ---------- ----------
- String: 3
- tool:795ms. --:1483ms. ap:1935ms. lib:2810ms. reg:6179ms.
- tool:874ms. --:1733ms. ap:1810ms. lib:2638ms. reg:6102ms.
- tool:921ms. --:1733ms. ap:1810ms. lib:2903ms. reg:6476ms.
- tool:983ms. --:1717ms. ap:1858ms. lib:2716ms. reg:5978ms.
- tool:1030ms. --:1702ms. ap:1764ms. lib:2778ms. reg:6040ms.
- tool:842ms. --:1842ms. ap:1904ms. lib:2966ms. reg:6274ms.
- tool:858ms. --:1515ms. ap:1655ms. lib:2513ms. reg:5884ms.
- StringTool: 6303 ms.
- Direct: 11725 ms.
- WholeApacheUtils: 12736 ms.
- JavaLib: 19324 ms.
- WholeRegex: 42933 ms.
- ---------- ---------- ---------- ----------
- String: 0
- tool:967ms. --:1795ms. ap:1966ms. lib:3043ms. reg:6226ms.
- tool:921ms. --:1733ms. ap:2014ms. lib:3029ms. reg:6212ms.
- tool:764ms. --:1452ms. ap:1608ms. lib:2357ms. reg:5883ms.
- tool:921ms. --:1515ms. ap:1701ms. lib:2575ms. reg:6040ms.
- tool:764ms. --:1499ms. ap:1576ms. lib:2762ms. reg:5980ms.
- tool:811ms. --:1452ms. ap:1671ms. lib:2466ms. reg:5696ms.
- tool:842ms. --:1576ms. ap:1733ms. lib:2747ms. reg:6070ms.
- StringTool: 5990 ms.
- Direct: 11022 ms.
- WholeApacheUtils: 12269 ms.
- JavaLib: 18979 ms.
- WholeRegex: 42107 ms.
- ---------- ---------- ---------- ----------
- String: -597213859710830758190748937102794
- tool:24039ms. ap:26162ms. lib:28955ms. --:31283ms. reg:56618ms.
- tool:23681ms. ap:25897ms. lib:29876ms. --:31235ms. reg:56960ms.
- tool:25194ms. ap:26927ms. --:29237ms. lib:29441ms. reg:57038ms.
- tool:24367ms. ap:25367ms. lib:29034ms. --:31250ms. reg:55431ms.
- tool:26567ms. ap:28689ms. lib:30859ms. --:34152ms. reg:61110ms.
- tool:25225ms. ap:26085ms. lib:29657ms. --:31266ms. reg:58692ms.
- tool:25366ms. ap:27332ms. lib:29611ms. --:30813ms. reg:58005ms.
- StringTool: 174439 ms.
- WholeApacheUtils: 186459 ms.
- JavaLib: 207433 ms.
- Direct: 219236 ms.
- WholeRegex: 403854 ms.
- ---------- ---------- ---------- ----------
- String: 78 9254 3253 2452 9572 8532
- tool:21731ms. ap:23136ms. lib:23949ms. --:28848ms. reg:47928ms.
- tool:20467ms. ap:22403ms. lib:23636ms. --:27942ms. reg:49237ms.
- tool:19625ms. ap:22964ms. lib:24385ms. --:27849ms. reg:48177ms.
- tool:21653ms. ap:23775ms. lib:24650ms. --:27614ms. reg:49236ms.
- tool:20795ms. ap:23073ms. lib:24088ms. --:29283ms. reg:48347ms.
- tool:21279ms. ap:23167ms. lib:23761ms. --:29143ms. reg:48925ms.
- tool:20795ms. ap:22247ms. lib:24619ms. --:27725ms. reg:48864ms.
- StringTool: 146345 ms.
- WholeApacheUtils: 160765 ms.
- JavaLib: 169088 ms.
- Direct: 198404 ms.
- WholeRegex: 340714 ms.
- ---------- ---------- ---------- ----------
- String: 13205972138597109830758190748937102794
- --:29078ms. tool:47706ms. ap:49001ms. lib:49564ms. reg:80750ms.
- --:34102ms. tool:49079ms. ap:49392ms. lib:51841ms. reg:82761ms.
- --:28828ms. tool:45677ms. ap:47051ms. lib:49782ms. reg:81139ms.
- --:28407ms. tool:45553ms. ap:48003ms. lib:49829ms. reg:79642ms.
- --:27175ms. tool:46208ms. ap:47800ms. lib:48956ms. reg:79704ms.
- --:34757ms. tool:54679ms. ap:56864ms. lib:57816ms. reg:88221ms.
- --:28486ms. tool:47721ms. ap:48892ms. lib:49065ms. reg:81014ms.
- Direct: 210833 ms.
- StringTool: 336623 ms.
- WholeApacheUtils: 347003 ms.
- JavaLib: 356853 ms.
- WholeRegex: 573231 ms.
- ---------- ---------- ---------- ----------
我们可以看到,除了被转换数字太长的情况(30位数字以上)外,Spads 出品的 StringTool 都有非常明显的速度优势。 null 本身处理速度远远快于其它情况,即便是 StringTool ,也没有耽误多少执行时间。
┌────────────┐ │ 以下是51CTO独家 │ └────────────┘ 为什么 Spads 提供的 StringTool 能具有显著的性能优势呢? 首先,正则表达式本身就是一个功能强大、通用但执行速度较慢的东西。其优势在于复杂匹配;对于转换数值这种简单匹配,其性能测试稳居最末的结果足以说明一切。 结合程序,我们能发现我在这个方法中将去除空格和验证格式合二为一了。这种安排避免了异常。生成异常需要读取方法调用栈的全部内容,所以执行速度很慢。直接处理方法就是通过是否产生异常来判断转型效果。 在优化过程中,我发现 Character#isDigit(char) 方法具有极其快的执行效率,甚至要快于直接数值比较。我对于 CPU 缓存的利用方式也不太了解,不知道它们咋调度的。但是 Character#isDigit(char) 配合过滤空白字符、负号和小数点,就变得慢下来了。测试程序如下。- static private int[] charType = {
- 0,0,0,0,0, 0,0,0,0,1,
- 0,0,0,0,0, 0,0,0,0,0,
- 0,0,0,0,0, 0,0,0,0,0,
- 0,0,1,0,0, 0,0,0,0,0,
- 0,0,0,0,0, 2,3,0,4,4,
- 4,4,4,4,4, 4,4,4
- };
- public void testIsCharacter()
- {
- Runnable r;
- System.out.println("Loop times = " + this.loopNum);
- System.out.println("---------- ---------- ---------- ----------");
- final Map<String, Long> timeUsedCount =
- Collections.synchronizedMap(new HashMap<String, Long>());
- final char[] charSet = {
- '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
- 'a', 'B', ' ', '\t', '中', '垚'
- };
- for (int loop = -1; ++loop != 7; )
- {
- final AtomicInteger runThreadNum = new AtomicInteger(0);
- // StringTool
- r = new Runnable()
- {
- public void run()
- {
- Random ran = new Random();
- boolean hasEx = false;
- if (timeUsedCount.get("StringTool") == null)
- timeUsedCount.put("StringTool", 0L);
- long start = System.currentTimeMillis();
- boolean result = false;
- for (int index = -1; ++index != CharTest.this.loopNum; )
- {
- try
- {
- char testChar = CharTest.charSet[ran.nextInt(16)];
- result = CharTest.charType[testChar] == 4;
- }
- catch (Exception ex) { hasEx = true; }
- }
- long use = System.currentTimeMillis() - start;
- System.out.print("\ttool:" + use + "ms" + (hasEx ? "(EX)" : "") + '.');
- use += timeUsedCount.get("StringTool");
- timeUsedCount.put("StringTool", use);
- runThreadNum.addAndGet(-1);
- Thread.yield();
- }
- };
- runThreadNum.addAndGet(1);
- new Thread(r).start();
- // JavaLib
- r = new Runnable()
- {
- public void run()
- {
- Random ran = new Random();
- boolean hasEx = false;
- if (timeUsedCount.get("Character#isDigit(char)") == null)
- timeUsedCount.put("Character#isDigit(char)", 0L);
- long start = System.currentTimeMillis();
- boolean result = false;
- for (int index = -1; ++index != CharTest.this.loopNum; )
- {
- try
- {
- char testChar = CharTest.charSet[ran.nextInt(16)];
- result = Character.isDigit(testChar);
- }
- catch (Exception ex) { hasEx = true; }
- }
- long use = System.currentTimeMillis() - start;
- System.out.print("\tjava:" + use + "ms" + (hasEx ? "(EX)" : "") + '.');
- use += timeUsedCount.get("Character#isDigit(char)");
- timeUsedCount.put("Character#isDigit(char)", use);
- runThreadNum.addAndGet(-1);
- Thread.yield();
- }
- };
- runThreadNum.addAndGet(1);
- new Thread(r).start();
- while (runThreadNum.get() != 0)
- {
- try { Thread.sleep(10); } catch (Exception ex) { }
- Thread.yield();
- }
- for (int index = -1; ++index != 3; )
- {
- try { Thread.sleep(100); } catch (Exception ex) { }
- Thread.yield();
- }
- System.out.println();
- }
- SortedMap<Long, String> thisNumStrTimeUsed =
- Collections.synchronizedSortedMap(new TreeMap<Long, String>());
- for (String name: timeUsedCount.keySet())
- thisNumStrTimeUsed.put(timeUsedCount.get(name), name);
- for (Long time: thisNumStrTimeUsed.keySet())
- System.out.println(thisNumStrTimeUsed.get(time) + ": " + time + " ms.");
- System.out.println("---------- ---------- ---------- ----------");
- }
测试结果如下。
- Loop times = 5000 0000
- ---------- ---------- ---------- ----------
- java:860ms. tool:868ms.
- java:874ms. tool:882ms.
- java:901ms. tool:926ms.
- java:888ms. tool:904ms.
- java:892ms. tool:906ms.
- java:853ms. tool:876ms.
- java:834ms. tool:914ms.
- Character#isDigit(char): 6102 ms.
- StringTool: 6276 ms.
- ---------- ---------- ---------- ----------
由于在 Spads 提供的字符串转换成数值方法中,对字符的处理是判断数值与空格一并进行的,所以没有采用系统提供的 Character#isDigit(char) 方法。而通过系统判断以及阿帕奇工具,都受牵制于这个高效方法,没有办法更大改变程序结构了。
本文还发表在我的其它技术日志 CSDN : ITeye : 中国开源社区: