Skip to content

Instantly share code, notes, and snippets.

@thedeemon
Created June 26, 2019 09:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thedeemon/1f0e870bb509b503bb46fe0a63661675 to your computer and use it in GitHub Desktop.
Save thedeemon/1f0e870bb509b503bb46fe0a63661675 to your computer and use it in GitHub Desktop.
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