关于动态链接库效率的疑问……
大家在开发库的时候有没有遇到过这么个情况……比如说我在一个文件里写了个函数 F ,用某个编译选项编译成dll了,保存起来,把它叫 dllA 。
然后我又给这个 dll 加一大堆新功能,写在别的源文件里(多文件编程),然后和以前的那些文件(根本就没再编辑过)一起编译成一个新 dll ,叫 dllB 。
结果 dllB 里的 F 比 dllA 里的 F 就是要慢!
dllB 新功能加得越多这个慢得越厉害……
以前我写高精库,乘法写完,做个标准测试 5秒5 ,然后我再写除法、开方、高精数类……写完再去用原来的接口(同样底层)去测乘法,能测出 6秒2到6秒7 来。
有没有和我遇到一样的问题的?有没有解决方案?
附件是这个效应的一个示例,并不明显,下载着玩吧……
因为是新写的,两个 dll 版本之间只差了一个简陋的除法,速度还差不太大,但已经可测了(3%)。
无论是代码还是数据,计算机都需要装载到cache里面,特别是L1-cache通常不会太大。代码越大,cache利用率越低,性能降低是正常的 因为是新写的,两个 dll 版本之间只差了一个简陋的除法,速度还差不太大,但已经可测了(3%)。
特地跑到windows 10 (home basic,64bit)跑了下,看不出性能的孰优孰劣, 不知道楼主的结论是怎么得出来的。
讲真,真要PK性能,得把这些波动的方差因素给刨开。
C:\Users\wayne wang\Downloads\Test2>Test2.exe
n= 1 old= 0.000000024s new= 0.000000022s k=1.107849
n= 6 old= 0.000000121s new= 0.000000125s k=0.972932
n= 11 old= 0.000000341s new= 0.000000364s k=0.936302
n= 17 old= 0.000000793s new= 0.000000738s k=1.075663
n= 23 old= 0.000001318s new= 0.000001407s k=0.936686
n= 30 old= 0.000002131s new= 0.000002145s k=0.993392
n= 38 old= 0.000003372s new= 0.000003184s k=1.059103
n= 46 old= 0.000003974s new= 0.000004395s k=0.904326
n= 55 old= 0.000005954s new= 0.000005943s k=1.001892
n= 65 old= 0.000008486s new= 0.000007942s k=1.068431
n= 76 old= 0.000009630s new= 0.000009679s k=0.994909
n= 88 old= 0.000011937s new= 0.000012028s k=0.992362
n= 101 old= 0.000013072s new= 0.000012570s k=1.039915
n= 116 old= 0.000015322s new= 0.000015405s k=0.994650
n= 132 old= 0.000018439s new= 0.000017504s k=1.053417
n= 150 old= 0.000019424s new= 0.000019483s k=0.997002
n= 170 old= 0.000023551s new= 0.000023770s k=0.990791
n= 192 old= 0.000027891s new= 0.000025500s k=1.093780
n= 216 old= 0.000030855s new= 0.000030870s k=0.999511
n= 242 old= 0.000055918s new= 0.000066150s k=0.845320
n= 271 old= 0.000078149s new= 0.000076651s k=1.019547
n= 303 old= 0.000083429s new= 0.000083342s k=1.001041
n= 338 old= 0.000101625s new= 0.000099155s k=1.024916
n= 376 old= 0.000115250s new= 0.000097653s k=1.180198
n= 418 old= 0.000110113s new= 0.000111563s k=0.987006
n= 464 old= 0.000129572s new= 0.000129836s k=0.997965
n= 515 old= 0.000153968s new= 0.000154637s k=0.995671
n= 571 old= 0.000222254s new= 0.000241395s k=0.920707
n= 633 old= 0.000289446s new= 0.000290832s k=0.995234
n= 701 old= 0.000340192s new= 0.000338934s k=1.003712
n= 776 old= 0.000392836s new= 0.000391093s k=1.004456
n= 858 old= 0.000408315s new= 0.000405057s k=1.008044
n= 948 old= 0.000471824s new= 0.000476981s k=0.989189
n= 1047 old= 0.000548420s new= 0.000503234s k=1.089791
n= 1156 old= 0.000528549s new= 0.000529367s k=0.998454
n= 1276 old= 0.000605036s new= 0.000742345s k=0.815034
n= 1408 old= 0.000932997s new= 0.000934308s k=0.998596
n= 1553 old= 0.001081213s new= 0.001036941s k=1.042695
n= 1713 old= 0.001140631s new= 0.001139323s k=1.001148
n= 1889 old= 0.001375002s new= 0.001373906s k=1.000797
n= 2082 old= 0.001641555s new= 0.001799596s k=0.912180
n= 2295 old= 0.001968195s new= 0.001941338s k=1.013835
n= 2529 old= 0.002047084s new= 0.002024859s k=1.010976
n= 2786 old= 0.002043208s new= 0.002043539s k=0.999838
n= 3069 old= 0.002467391s new= 0.002445752s k=1.008848
n= 3380 old= 0.002700648s new= 0.002441960s k=1.105935
n= 3723 old= 0.002610534s new= 0.002918671s k=0.894425
n= 4100 old= 0.003861612s new= 0.003845121s k=1.004289
n= 4515 old= 0.003981123s new= 0.003937971s k=1.010958
n= 4971 old= 0.004029291s new= 0.003903388s k=1.032255
n= 5473 old= 0.004406561s new= 0.004390821s k=1.003585
n= 6025 old= 0.004619760s new= 0.004571099s k=1.010645
n= 6632 old= 0.004386186s new= 0.004396780s k=0.997590
n= 7300 old= 0.006758158s new= 0.006757489s k=1.000099
n= 8035 old= 0.006704585s new= 0.006746277s k=0.993820
n= 8843 old= 0.008255253s new= 0.007665426s k=1.076946
n= 9732 old= 0.007941157s new= 0.007918547s k=1.002855
n= 10710 old= 0.009915795s new= 0.010221086s k=0.970131
n= 11786 old= 0.010470380s new= 0.010548351s k=0.992608
n= 12969 old= 0.012445101s new= 0.011374011s k=1.094170
n= 14270 old= 0.011517089s new= 0.011503174s k=1.001210
n= 15702 old= 0.012877944s new= 0.012654910s k=1.017624
n= 17277 old= 0.014539538s new= 0.013099886s k=1.109898
n= 19009 old= 0.014920787s new= 0.014810057s k=1.007477
n= 20914 old= 0.016542852s new= 0.016378280s k=1.010048
n= 23010 old= 0.014291510s new= 0.014033253s k=1.018403
n= 25316 old= 0.017927203s new= 0.017864952s k=1.003484
n= 27852 old= 0.019303878s new= 0.017847814s k=1.081582
n= 30642 old= 0.017861707s new= 0.028196246s k=0.633478
n= 33711 old= 0.043148525s new= 0.041062667s k=1.050797
n= 37087 old= 0.039806241s new= 0.043441068s k=0.916327
n= 40800 old= 0.045152868s new= 0.044156524s k=1.022564
n= 44885 old= 0.052691691s new= 0.050483430s k=1.043742
n= 49378 old= 0.058225116s new= 0.064445158s k=0.903483
n= 54320 old= 0.067874685s new= 0.067835376s k=1.000579
n= 59757 old= 0.069337794s new= 0.065724564s k=1.054975
n= 65737 old= 0.082554766s new= 0.089835153s k=0.918958
n= 72315 old= 0.093310507s new= 0.092773223s k=1.005791
n= 79551 old= 0.093444432s new= 0.102110694s k=0.915129
n= 87511 old= 0.113418532s new= 0.111709695s k=1.015297
n= 96267 old= 0.102095681s new= 0.102070003s k=1.000252
n=105898 old= 0.129441822s new= 0.129353328s k=1.000684
n=116492 old= 0.135941370s new= 0.147335331s k=0.922666
n=128146 old= 0.143794397s new= 0.144994594s k=0.991722
n=140965 old= 0.211887551s new= 0.195057942s k=1.086280
n=155066 old= 0.205429485s new= 0.218515494s k=0.940114
n=170577 old= 0.265852129s new= 0.239870531s k=1.108315
n=187639 old= 0.264717909s new= 0.283754725s k=0.932911
n=206407 old= 0.317136612s new= 0.296807549s k=1.068492
n=227052 old= 0.296130415s new= 0.263996131s k=1.121723
n=249762 old= 0.252896490s new= 0.330007313s k=0.766336
n=274743 old= 0.447202235s new= 0.415956445s k=1.075118
n=302222 old= 0.461456836s new= 0.521026938s k=0.885668
n=332449 old= 0.558315190s new= 0.446828112s k=1.249508
n=365698 old= 0.525418044s new= 0.549413670s k=0.956325
n=402272 old= 0.677507148s new= 0.621180498s k=1.090677
n=442504 old= 0.619767759s new= 0.632566954s k=0.979766
n=486759 old= 0.675212237s new= 0.621656547s k=1.086150
n=535439 old= 0.993022428s new= 0.871779312s k=1.139075
n=588987 old= 1.009444335s new= 1.027876708s k=0.982068
n=647890 old= 1.080180448s new= 0.873409730s k=1.236740
n=712684 old= 1.224462746s new= 0.970016035s k=1.262312
n=783957 old= 1.339919400s new= 1.009498063s k=1.327313
n=862357 old= 1.486679127s new= 1.371393140s k=1.084065
n=948597 old= 1.527866634s new= 1.118768057s k=1.365669
n= 1043461 old= 1.486694534s new= 1.534411218s k=0.968902
n= 1147812 old= 1.903586880s new= 1.327169192s k=1.434321
n= 1262598 old= 1.110784659s new= 0.930777366s k=1.193395
n= 1388862 old= 1.832957828s new= 1.498450372s k=1.223236
n= 1527753 old= 2.249494618s new= 1.538607954s k=1.462032
n= 1680533 old= 2.489156951s new= 2.411986475s k=1.031995
n= 1848591 old= 3.090017474s new= 3.200192948s k=0.965572
n= 2033455 old= 2.754140736s new= 2.671732142s k=1.030845
n= 2236805 old= 2.094143888s new= 1.617689737s k=1.294528
n= 2460490 old= 1.685271287s new= 1.683493906s k=1.001056
n= 2706544 old= 1.879992636s new= 1.883690804s k=0.998037
n= 2977203 old= 2.082824198s new= 2.568004068s k=0.811067
n= 3274928 old= 4.945845398s new= 4.747115361s k=1.041863
n= 3602425 old= 2.835659652s new= 2.555579391s k=1.109596
n= 3962672 old= 4.921664883s new= 2.865660604s k=1.717463
n= 4358944 old= 3.228543334s new= 3.227516965s k=1.000318
n= 4794843 old= 5.673305276s new= 3.624403803s k=1.565307
n= 5274332 old= 7.662993782s new=10.608250538s k=0.722362
n= 5801770 old=11.751945775s new=10.221024528s k=1.149782
n= 6381952 old=11.837294415s new=12.546398957s k=0.943481
关于楼主在附件里的吐槽
附件大小必须小于256k……
winrar压完之后大于512k要分3个卷……
7z格式不能上传……
然后winrar还不能直接压缩压缩包……
所以我只能拿7z压完再写这么个文件用winrar压在一起分两卷上传…………
论坛确实 不太适合 交流较大的附件。推荐的方式提供一个网盘链接。 要么用自己的网盘的外链链接。要么使用本论坛的百度网盘【刚把网盘找回来,账号名和密码分别是数学研发论坛,emath@2017】 关于动态库方面 连接和加载 更细节方面的知识,可以看看这本电子书 《Advanced C and C++ Compiling》
http://www.allitebooks.com/advanced-c-and-c-compiling/ 5#的书download下来了,搂了一眼。发现制作的还不错,插图还是彩色的。
页:
[1]