char array weirdness
ag0aep6g via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Mar 31 05:49:57 PDT 2016
On 31.03.2016 07:40, Jack Stouffer wrote:
> $ ldc2 -O3 -release -boundscheck=off test.d
> $ ./test
> auto-decoding 1 sec, 757 ms, and 946 μs
> byCodeUnit 87 ms, 731 μs, and 8 hnsecs
> byGrapheme 14 secs, 769 ms, 796 μs, and 6 hnsecs
So the auto-decoding version takes about twenty times as long as the
non-decoding one (1758 / 88 ≅ 20).
I still think the allocations from the `.array` calls should be
eliminated to see how just iterating compares.
Here's a quick edit to get rid of the `.array`s:
----
uint accumulator = 0;
void test(char[] var)
{
foreach (dchar d; var) accumulator += d;
}
void test2(char[] var)
{
foreach (c; var.byCodeUnit) accumulator += c;
}
----
I get theses timings then:
----
auto-decoding 642 ms, 969 μs, and 1 hnsec
byCodeUnit 84 ms, 980 μs, and 3 hnsecs
----
And 643 / 85 ≅ 8.
More information about the Digitalmars-d-learn
mailing list