Skip to content

Instantly share code, notes, and snippets.

@atilaneves
Created March 31, 2014 12:11
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 atilaneves/9890945 to your computer and use it in GitHub Desktop.
Save atilaneves/9890945 to your computer and use it in GitHub Desktop.
Cerealed performance test
import cerealed.cerealiser;
import cerealed.decerealiser;
struct FooStruct {
int i;
int j;
string str;
double d;
}
enum Old = is(Cerealiser == class);
enum useScope = true;
void main(string[] args) {
if(args.length && args[1] == "d") {
testDecerealiser();
} else {
testCerealiser();
}
}
void testCerealiser() {
enum enc_loops = 25_000_000;
for(int i = 0; i < enc_loops; ++i) {
static if(Old) {
auto enc = new Cerealiser;
} else {
alias MyCerealiser = Cerealiser;
static if(useScope) {
import cerealed.range;
ubyte[6] buf = void;
auto sbufRange = ScopeBufferRange(buf);
scope(exit) sbufRange.free();
auto enc = CerealiserImpl!ScopeBufferRange(sbufRange);
} else {
auto enc = MyCerealiser();
}
}
enc ~= FooStruct(i, i + 1, "foo", i + 2);
}
}
void testDecerealiser() {
enum dec_loops = 75_000_000;
ubyte[] mybytes = [0, 0, 0, 3, 0, 0, 0, 2, 0, 3, 'b', 'a', 'r', 0, 0, 0, 0, 0, 0, 0, 0];
for(int i = 0; i < dec_loops; ++i) {
static if(Old) {
auto dec = new Decerealiser(mybytes);
} else {
auto dec = Decerealiser(mybytes);
}
const foo = dec.value!FooStruct;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment