Am Sun, 16 Nov 2014 13:39:22 +0000 schrieb "FrankLike" <1150015...@qq.com>:
> Many old projects need move from x86 to x64,but the 'length' type > is size_t,it will change on x64,so a lot of work must to do.but I > find some info which is help for d: > http://www.dotnetperls.com/array-length. > it means: > test length and longlength, and found 'test longlength' is > slower than 'test length'. > > 0.64 ns Length > 2.55 ns LongLength > > I love D.So I don't want my app on x64 slower than on x86. > > Hope change in 2.067. > > Thank you all. No, you will not get 'int' instead of 'size_t' in 2.067 because a dubious showed you it is faster. In fact when you write the code like this and use 1000 times more iterations to get a reading at all, it looks like this: -------------------------- import std.stdio; import std.datetime; alias ℕ = size_t; void ada() { foreach (ℕ i; 0 .. 1_000_000_000) {} } void main() { StopWatch sw; sw.start(); ada(); sw.stop(); writefln("time is: %s secs", sw.peek().msecs/1000.0); } ------------------------ And prints 0.461 secs for both dmd -m32 -boundscheck=off -release -inline -O and dmd -m64 -boundscheck=off -release -inline -O on my laptop. When I change 'ada' to: ℕ ada() { ℕ v; foreach (ℕ i; 0 .. 1_000_000_000) { v = i+i; } return v; } the -m64 version becomes a lot slower (0.731 secs) compared to the -m32 version (which stays at 0.461 secs). That does not have to do with size_t though: If I change the definition of ℕ to uint or int in the 64-bit version it stays slow. It is just a difference in the generated code for the loop that makes the 64-bit version generally 270 ms slower. Now to get some more interesting numbers let's chose an operation that is inherently O(n) in regards to bit-width: division ℕ ada() { ℕ v; foreach (ℕ i; 1 .. 1_000_000_001) { v = i/i; } return v; } Results: alias ℕ = ulong: 17.07 secs alias ℕ = uint: 5.80 secs alias ℕ = int: 5.53 secs The differences for uint and int are compiler dependent. With LDC uint is faster than int by a similar amount. -- Marco