Skip to content

Instantly share code, notes, and snippets.

@DmitryOlshansky
Created March 15, 2014 15:52
Show Gist options
  • Select an option

  • Save DmitryOlshansky/9569368 to your computer and use it in GitHub Desktop.

Select an option

Save DmitryOlshansky/9569368 to your computer and use it in GitHub Desktop.
Tiny benchmark for scopebuffer
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