Created
June 26, 2019 09:57
-
-
Save thedeemon/1f0e870bb509b503bb46fe0a63661675 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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