-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
89 additions
and
109 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,82 +1,38 @@ | ||
import { JSON } from ".."; | ||
import { _deserializeString, deserializeString } from "../deserialize/string"; | ||
import { Sink } from "../src/sink"; | ||
|
||
import { bench, blackbox } from "as-bench/assembly/bench"; | ||
import { __atoi_fast, __atoi_fast_safe } from "../src/util"; | ||
import { serializeUnknown } from "../serialize/unknown"; | ||
import { Sink } from "../src/sink"; | ||
import { JSON } from ".."; | ||
|
||
const set = JSON.Value.from([ | ||
JSON.Value.from([]), | ||
JSON.Value.from([ | ||
JSON.Value.from([]) | ||
JSON.Value.from([]) | ||
]), | ||
JSON.Value.from([ | ||
JSON.Value.from([]), | ||
JSON.Value.from([ | ||
JSON.Value.from([]) | ||
]), | ||
JSON.Value.from([]), | ||
JSON.Value.from([ | ||
JSON.Value.from([]) | ||
]), | ||
]), | ||
]); | ||
|
||
@unmanaged | ||
class Vec3 { | ||
x: f64; | ||
y: f64; | ||
z: f64; | ||
@inline __JSON_Serialize(out: Sink | null = null): Sink { | ||
if (!out) { | ||
out = Sink.withCapacity(25); | ||
} | ||
|
||
out.write(this.__JSON_Serialize_Unsafe()); | ||
|
||
return out; | ||
} | ||
@inline __JSON_Serialize_Unsafe(): string { | ||
return `{"x":${JSON.serialize<f64>(this.x)},"y":${JSON.serialize<f64>(this.y)},"z":${JSON.serialize<f64>(this.z)}}`; | ||
} | ||
} | ||
|
||
const vec: Vec3 = { | ||
x: 3.4, | ||
y: 1.2, | ||
z: -5.6 | ||
} | ||
|
||
const map = new Map<string, JSON.Value>(); | ||
map.set("x", JSON.Value.from<f64>(3.4)); | ||
map.set("y", JSON.Value.from<f64>(1.2)); | ||
map.set("z", JSON.Value.from<f64>(-5.6)); | ||
/* | ||
bench("Serialize Set Theoretical Representation", () => { | ||
blackbox<Sink>(serializeUnknown(set)); | ||
}); | ||
bench("Serialize Vector 3 Struct", () => { | ||
blackbox<string>(vec.__JSON_Serialize_Unsafe()); | ||
}); | ||
bench("Serialize String (Sink)", () => { | ||
blackbox<Sink>(JSON.serialize<string>("hello world")); | ||
blackbox<Sink>(JSON.serialize(set)); | ||
}); | ||
bench("Serialize String (No Sink)", () => { | ||
blackbox<string>(JSON.serialize<string>("hello world").toString()); | ||
/*bench("Serialize Float", () => { | ||
blackbox<Sink>(JSON.serialize<f64>(1.2345)); | ||
}); | ||
bench("Parse String (Raw)", () => { | ||
blackbox<string>(_deserializeString("\"hello world\"")); | ||
bench("Serialize Float32", () => { | ||
blackbox<Sink>(JSON.serialize<f32>(1.2345)); | ||
}); | ||
bench("Parse String (Product)", () => { | ||
blackbox<ProductValue>(JSON.parse<string>("\"hello world\"")); | ||
bench("Serialize String", () => { | ||
blackbox<Sink>(JSON.serialize("hello world")); | ||
}); | ||
bench("Parse String (Unwrap)", () => { | ||
blackbox<string>(JSON.parse<string>("\"hello world\"").unwrap<string>()); | ||
});*/ | ||
bench("ATOI (Unsafe): " + __atoi_fast<u32>("1234567890").toString(), () => { | ||
blackbox<u32>(__atoi_fast<u32>("1234567890")); | ||
bench("Serialize Integer", () => { | ||
blackbox<Sink>(JSON.serialize(12345)); | ||
}); | ||
bench("ATOI (Safe): " + __atoi_fast_safe<u32>("1234567890").toString(), () => { | ||
blackbox<u32>(__atoi_fast_safe<u32>("1234567890")); | ||
}); | ||
bench("empty", () => {}) | ||
bench("Parse Number: " + __atoi_fast<u32>("12345").toString(), () => { | ||
blackbox<u32>(__atoi_fast<u32>("12345")); | ||
});*/ |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import Benchmark from "benchmark"; | ||
const suite = new Benchmark.Suite; | ||
|
||
suite.add("Serialize Set Theoretical Representation", () => { | ||
JSON.stringify([[],[[]],[[],[[]]]]); | ||
}); | ||
/* | ||
suite.add("Serialize Float", () => { | ||
JSON.stringify(1.2345); | ||
}); | ||
suite.add("Serialize Integer", () => { | ||
JSON.stringify(12345); | ||
}); | ||
suite.add("Serialize String", () => { | ||
JSON.stringify("hello world"); | ||
}); | ||
suite.add("Parse Number", () => { | ||
JSON.parse("12345"); | ||
}); | ||
*/ | ||
suite.on("cycle", (cycle) => { | ||
console.log(cycle.target.toString()); | ||
}); | ||
|
||
|
||
suite.run(); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export { JSON } from "./assembly/src/json"; | ||
|
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