Skip to content

Instantly share code, notes, and snippets.

@thedeemon thedeemon/tox.d
Created Jun 26, 2019

Embed
What would you like to do?
import std.stdio, std.algorithm, std.range, std.array, std.datetime.stopwatch;
struct Point { int x, y; }
auto f(int from_y, int to_y, int from_x, int to_x) {
return chain( iota(from_y, to_y/2).map!(y => Point(from_x, y)),
iota(to_y/2, to_y) .map!(y => Point(to_x, y)) ).array;
}
auto g(int from_y, int to_y, int from_x, int to_x) {
auto res = new Point[to_y - from_y];
foreach(y; from_y .. to_y)
res[y - from_y] = Point(y < to_y / 2 ? from_x : to_x, y);
return res;
}
void main() {
auto sw = StopWatch(AutoStart.yes);
auto r1 = f(20_000_000, 80_000_000, 1, 2);
auto t1 = sw.peek();
auto r2 = g(20_000_000, 80_000_000, 1, 2);
auto t2 = sw.peek();
writefln("f: %s, g: %s\t%s %s", t1, t2-t1, r1[$-1], r2[$-1]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.