xxxxxxxxxx
import std.stdio: writeln;
import std.algorithm: each, fill, equal;
import std.range: stride;
import std.datetime.stopwatch: benchmark;
enum Mb = 1024*1024;
void main()
{
enum strideAmount = 3;
enum arraySize = 50 * Mb;
alias Type = byte;
auto a = new Type[arraySize/Type.sizeof];
auto b = new Type[arraySize/Type.sizeof];
auto c = new Type[arraySize/Type.sizeof];
a[] = -1;
b[] = -1;
c[] = -1;
benchmark!({
for(auto i=0; i<a.length; i+=strideAmount) {
a[i] = 0;
}
}, {
b[0..$].stride(strideAmount).fill(cast(Type) 0); //yes the cast is needed for smaller types like byte
}, {
c[0..$].stride(strideAmount).each!((ref x) => x = 0);
})(1).each!writeln;
assert(a.equal(b) && b.equal(c));
}