Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.