Created
March 15, 2014 15:52
-
-
Save DmitryOlshansky/9569368 to your computer and use it in GitHub Desktop.
Tiny benchmark for scopebuffer
This file contains hidden or 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 scopebuf; | |
| //import std.buffer.scopebuffer; | |
| import std.datetime, std.conv, std.stdio, std.exception; | |
| int do_build(int n) | |
| { | |
| char[80] store = void; | |
| auto buf = scopeBuffer(store[]); | |
| //scope(exit) buf.free(); | |
| for(int i=0; i<n;i++) | |
| buf.put('X'); | |
| auto ret = buf[]; | |
| int sum = 0; | |
| for(int i=0; i<n; i++) | |
| sum += ret[i]; | |
| return sum; | |
| } | |
| void main(string argv[]) | |
| { | |
| int num; | |
| enforce(argv.length == 2); | |
| num = to!int(argv[1]); | |
| StopWatch sw; | |
| sw.start(); | |
| int total = 0; | |
| foreach(_; 0..10_000) | |
| total += do_build(num); | |
| sw.stop(); | |
| writeln(total, " time: ", sw.peek().usecs, "us"); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment