作者virdust2003 (替机壳洗个热水澡)
看板C_Sharp
标题[讨论] Use Jagged Arrays
时间Tue Nov 22 15:25:56 2005
Performance Tips and Tricks in .NET Applications
文章Title
不知道为什麽 Jagged Arrays 会比 Rectangular arrays 好?
Use Jagged Arrays—Version 1
The v1 JIT optimizes jagged arrays (simply 'arrays-of-arrays') more
efficiently than rectangular arrays, and the difference is quite noticeable.
Here is a table demonstrating the performance gain resulting from using
jagged arrays in place of rectangular ones in both C# and Visual Basic
(higher numbers are better):
C# Visual Basic 7
Assignment (jagged) Assignment (rectangular)
14.16 8.37
12.24 8.62
Neural Net (jagged) Neural net (rectangular)
4.48 3.00
4.58 3.13
Numeric Sort (jagged) Numeric Sort (rectangular)
4.88 2.05
5.07 2.06
The assignment benchmark is a simple assignment algorithm, adapted from the
step-by-step guide found in Quantitative Decision Making for Business
(Gordon, Pressman, and Cohn; Prentice-Hall; out of print). The neural net
test runs a series of patterns over a small neural network, and the numeric
sort is self-explanatory. Taken together, these benchmarks represent a good
indication of real-world performance.
As you can see, using jagged arrays can result in fairly dramatic performance
increases. The optimizations made to jagged arrays will be added to future
versions of the JIT, but for v1 you can save yourself a lot of time by using
jagged arrays.
--
-----------------------------------------------------------------------------
功课重,Project多的好帮手--专案王
http://steven.twbbs.org/ProjectKing
增加右键的威力RightMenuKing--右键王
http://steven.twbbs.org/RightMenuKing/
备份重要档案的好帮BackupKing--备份王
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.113.216.156
1F:推 glenn7012:可能用jagged方式宣告的array比较有弹性 11/23 01:21
2F:推 virdust2003:一般弹性跟效率都是反比的 11/25 00:50