json-as 1.0.0-beta.17 → 1.0.0-beta.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{CHANGELOG → CHANGELOG.md} +7 -1
- package/README.md +80 -66
- package/assembly/__benches__/abc.bench.ts +22 -0
- package/assembly/__benches__/large.bench.ts +174 -0
- package/assembly/__benches__/medium.bench.ts +46 -0
- package/assembly/__benches__/small.bench.ts +33 -0
- package/assembly/__benches__/vec3.bench.ts +73 -0
- package/assembly/__tests__/arbitrary.spec.ts +3 -3
- package/assembly/__tests__/array.spec.ts +5 -8
- package/assembly/__tests__/box.spec.ts +10 -20
- package/assembly/__tests__/custom.spec.ts +7 -6
- package/assembly/__tests__/date.spec.ts +4 -6
- package/assembly/__tests__/float.spec.ts +3 -3
- package/assembly/__tests__/lib/index.ts +4 -0
- package/assembly/__tests__/map.spec.ts +1 -1
- package/assembly/__tests__/misc.spec.ts +90 -0
- package/assembly/__tests__/raw.spec.ts +3 -3
- package/assembly/__tests__/struct.spec.ts +3 -6
- package/assembly/custom/bench.ts +9 -2
- package/assembly/deserialize/simple/array/struct.ts +2 -3
- package/assembly/deserialize/simple/array.ts +1 -1
- package/assembly/deserialize/simple/bool.ts +1 -1
- package/assembly/deserialize/simple/map.ts +3 -4
- package/assembly/deserialize/simple/object.ts +2 -3
- package/assembly/deserialize/simple/raw.ts +1 -1
- package/assembly/deserialize/simple/struct.ts +9 -5
- package/assembly/index.ts +14 -5
- package/assembly/serialize/simple/arbitrary.ts +1 -0
- package/assembly/serialize/simple/array.ts +1 -0
- package/assembly/serialize/simple/bool.ts +1 -0
- package/assembly/serialize/simple/date.ts +1 -0
- package/assembly/serialize/simple/float.ts +1 -0
- package/assembly/serialize/simple/integer.ts +2 -1
- package/assembly/serialize/simple/map.ts +1 -0
- package/assembly/serialize/simple/object.ts +4 -3
- package/assembly/serialize/simple/raw.ts +1 -0
- package/assembly/serialize/simple/string.ts +1 -0
- package/assembly/test.ts +63 -39
- package/bench/abc.bench.ts +20 -0
- package/bench/large.bench.ts +126 -0
- package/bench/medium.bench.ts +43 -0
- package/bench/small.bench.ts +30 -0
- package/bench/vec3.bench.ts +26 -0
- package/index.ts +1 -1
- package/{lib → modules}/as-bs.ts +4 -13
- package/package.json +5 -3
- package/run-bench.as.sh +15 -0
- package/run-bench.js.sh +12 -0
- package/run-tests.sh +1 -1
- package/transform/lib/index.js +25 -45
- package/transform/lib/index.js.map +1 -1
- package/transform/src/index.ts +31 -72
- package/assembly/__benches__/misc.bench.ts +0 -47
- package/assembly/__benches__/schemas.ts +0 -25
- package/assembly/__benches__/string.bench.ts +0 -23
- package/assembly/__benches__/struct.bench.ts +0 -21
- package/assembly/as-bs.d.ts +0 -53
- package/bench/schemas.ts +0 -5
- package/bench/string.bench.ts +0 -16
- package/bench.js +0 -85
- /package/bench/{bench.ts → lib/bench.ts} +0 -0
- /package/{lib → modules}/tsconfig.json +0 -0
package/assembly/as-bs.d.ts
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Central buffer namespace for managing memory operations.
|
|
3
|
-
*/
|
|
4
|
-
declare namespace bs {
|
|
5
|
-
/** Current buffer pointer. */
|
|
6
|
-
export let buffer: ArrayBuffer;
|
|
7
|
-
|
|
8
|
-
/** Current offset within the buffer. */
|
|
9
|
-
export let offset: usize;
|
|
10
|
-
|
|
11
|
-
/** Proposed size of output. */
|
|
12
|
-
export let stackSize: usize;
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Ensures the buffer size is at least the proposed size.
|
|
16
|
-
* If necessary, reallocates the buffer to the exact new size.
|
|
17
|
-
* @param size - The size to propose.
|
|
18
|
-
*/
|
|
19
|
-
export function ensureSize(size: u32): void;
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Proposes that the buffer size should be at least the given size.
|
|
23
|
-
* If necessary, reallocates the buffer to the exact new size.
|
|
24
|
-
* @param size - The size to propose.
|
|
25
|
-
*/
|
|
26
|
-
export function proposeSize(size: u32): void;
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Increases the proposed size by nextPowerOf2(n + 64) if necessary.
|
|
30
|
-
* If necessary, reallocates the buffer to the exact new size.
|
|
31
|
-
* @param size - The size to grow by.
|
|
32
|
-
*/
|
|
33
|
-
export function growSize(size: u32): void;
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Resizes the buffer to the specified size.
|
|
37
|
-
* @param newSize - The new buffer size.
|
|
38
|
-
*/
|
|
39
|
-
export function resize(newSize: u32): void;
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Copies the buffer's content to a new object of a specified type.
|
|
43
|
-
* @returns The new object containing the buffer's content.
|
|
44
|
-
*/
|
|
45
|
-
export function out<T>(): T;
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Copies the buffer's content to a given destination pointer.
|
|
49
|
-
* @param dst - The destination pointer.
|
|
50
|
-
* @returns The destination pointer cast to the specified type.
|
|
51
|
-
*/
|
|
52
|
-
export function outTo<T>(dst: usize): T;
|
|
53
|
-
}
|
package/bench/schemas.ts
DELETED
package/bench/string.bench.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { bench } from "./bench";
|
|
2
|
-
import { Vec3 } from "./schemas";
|
|
3
|
-
|
|
4
|
-
const vec: Vec3 = {
|
|
5
|
-
x: 1,
|
|
6
|
-
y: 2,
|
|
7
|
-
z: 3,
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
bench("Serialize Vector3", () => {
|
|
11
|
-
JSON.stringify(vec);
|
|
12
|
-
}, 25_000_000);
|
|
13
|
-
|
|
14
|
-
bench("Deserialize Vector3", () => {
|
|
15
|
-
JSON.parse('{"x":1,"y":2,"z":3}');
|
|
16
|
-
}, 25_000_000);
|
package/bench.js
DELETED
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import { Bench } from "tinybench";
|
|
2
|
-
// Trying a new benchmarking lib.
|
|
3
|
-
|
|
4
|
-
// JavaScript Results
|
|
5
|
-
// ┌─────────┬───────────────────────────┬─────────────┬────────────────────┬──────────┬─────────┐
|
|
6
|
-
// │ (index) │ Task Name │ ops / sec │ Average Time(ns) │ Margin │ Samples │
|
|
7
|
-
// ├─────────┼───────────────────────────┼─────────────┼────────────────────┼──────────┼─────────┤
|
|
8
|
-
// │ 0 │ 'Stringify Object (Vec3)' │ '817,816' │ 1222.76 │ '±3.55%' │ 81782 │
|
|
9
|
-
// │ 1 │ 'Parse Object (Vec3)' │ '726,115' │ 1377.19 │ '±3.21%' │ 72612 │
|
|
10
|
-
// │ 2 │ 'Stringify Number Array' │ '1,104,036' │ 905.77 │ '±6.48%' │ 110404 │
|
|
11
|
-
// │ 3 │ 'Parse Number Array' │ '1,114,053' │ 897.62 │ '±2.58%' │ 111406 │
|
|
12
|
-
// │ 4 │ 'Stringify String' │ '1,565,716' │ 638.69 │ '±2.04%' │ 156572 │
|
|
13
|
-
// │ 5 │ 'Parse String' │ '69,568' │ 14374.22 │ '±2.55%' │ 6957 │
|
|
14
|
-
// └─────────┴───────────────────────────┴─────────────┴────────────────────┴──────────┴─────────┘
|
|
15
|
-
|
|
16
|
-
// AssemblyScript Results (Runtime Minimal)
|
|
17
|
-
// ┌─────────┬───────────────────────────┬─────────────┬────────────────────┬──────────┬─────────┐
|
|
18
|
-
// │ (index) │ Task Name │ ops / sec │ Average Time(ns) │ Diff │ Samples │
|
|
19
|
-
// ├─────────┼───────────────────────────┼─────────────┼────────────────────┼──────────┼─────────┤
|
|
20
|
-
// │ 0 │ 'Stringify Object (Vec3)' │ '2,091,000' │ 417.22 │ -805ns │ ------- │
|
|
21
|
-
// │ 1 │ 'Parse Object (Vec3)' │ '1,780,000' │ 539.02 │ -838ns │ ------- |
|
|
22
|
-
// │ 2 │ 'Stringify Number Array' │ '1,920,000' │ 445.43 │ -460ns │ ------- │
|
|
23
|
-
// │ 3 │ 'Parse Number Array' │ '1,660,000' │ 597.17 │ -300ns │ ------- │
|
|
24
|
-
// │ 4 │ 'Stringify String' │ '1,280,000' │ 736.27 │ +97ns │ ------- │
|
|
25
|
-
// │ 5 │ 'Parse String' │ '4,230,000' │ 239.21 │ -14135ns │ ------- │
|
|
26
|
-
// └─────────┴───────────────────────────┴─────────────┴────────────────────┴──────────┴─────────┘
|
|
27
|
-
|
|
28
|
-
const vec = {
|
|
29
|
-
x: 3,
|
|
30
|
-
y: 1,
|
|
31
|
-
z: 8,
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
let data;
|
|
35
|
-
|
|
36
|
-
const bench = new Bench({ time: 1000 })
|
|
37
|
-
.add("serialize vec3", () =>
|
|
38
|
-
data = JSON.stringify(vec)
|
|
39
|
-
)
|
|
40
|
-
.add("deserialize vec3", () => {
|
|
41
|
-
data = JSON.parse('{"x":3,"y":1,"z":8}');
|
|
42
|
-
})
|
|
43
|
-
.add("serialize alphabet string", () => {
|
|
44
|
-
data = JSON.stringify("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789~`!@#$%^&*()-_=+{[}]|\\:;\"'?/>.<,'\"}");
|
|
45
|
-
})
|
|
46
|
-
.add("deserialize alphabet string", () => {
|
|
47
|
-
data = JSON.parse('"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789~`!@#$%^&*()-_=+{[}]|\\\\:;\\"\'?/>.<,\'\\"}"')
|
|
48
|
-
}) /*
|
|
49
|
-
.add("parse float", () => {
|
|
50
|
-
data = JSON.parse("1.2345")
|
|
51
|
-
})
|
|
52
|
-
.add("stringify iny", () => {
|
|
53
|
-
data = JSON.stringify(12345)
|
|
54
|
-
})
|
|
55
|
-
.add("parse int", () => {
|
|
56
|
-
data = JSON.parse("12345")
|
|
57
|
-
})
|
|
58
|
-
.add("Stringify Object (Vec3)", () => {
|
|
59
|
-
data = JSON.stringify(vec);
|
|
60
|
-
})
|
|
61
|
-
|
|
62
|
-
.add("Parse Object (Vec3)", () => {
|
|
63
|
-
data = JSON.parse('{"x":0,"y":0,"z":0}');
|
|
64
|
-
})
|
|
65
|
-
|
|
66
|
-
.add("Stringify Number Array", () => {
|
|
67
|
-
data = JSON.stringify([1, 2, 3]);
|
|
68
|
-
})
|
|
69
|
-
|
|
70
|
-
.add("Parse Number Array", () => {
|
|
71
|
-
data = JSON.parse("[1,2,3]");
|
|
72
|
-
})
|
|
73
|
-
|
|
74
|
-
.add("Stringify String", () => {
|
|
75
|
-
data = JSON.stringify('Hello "World!');
|
|
76
|
-
})
|
|
77
|
-
|
|
78
|
-
.add("Parse String", () => {
|
|
79
|
-
data = JSON.stringify('hello "world abc');
|
|
80
|
-
})*/
|
|
81
|
-
.todo("unimplemented .add");
|
|
82
|
-
|
|
83
|
-
await bench.run();
|
|
84
|
-
|
|
85
|
-
console.table(bench.table());
|
|
File without changes
|
|
File without changes
|