json-as 1.2.1 → 1.2.2-beta.1

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.
Files changed (79) hide show
  1. package/package.json +1 -1
  2. package/.github/FUNDING.yml +0 -1
  3. package/.github/dependabot.yml +0 -11
  4. package/.github/workflows/benchmark.yml +0 -72
  5. package/.github/workflows/release-package.yml +0 -47
  6. package/.github/workflows/tests.yml +0 -25
  7. package/.prettierignore +0 -9
  8. package/.prettierrc.json +0 -7
  9. package/.trunk/configs/.markdownlint.yaml +0 -2
  10. package/.trunk/configs/.shellcheckrc +0 -7
  11. package/.trunk/configs/.yamllint.yaml +0 -7
  12. package/.trunk/trunk.yaml +0 -37
  13. package/CHANGELOG.md +0 -334
  14. package/SECURITY.md +0 -32
  15. package/asconfig.json +0 -7
  16. package/assembly/__benches__/abc.bench.ts +0 -28
  17. package/assembly/__benches__/large.bench.ts +0 -238
  18. package/assembly/__benches__/lib/bench.ts +0 -85
  19. package/assembly/__benches__/medium.bench.ts +0 -128
  20. package/assembly/__benches__/small.bench.ts +0 -46
  21. package/assembly/__benches__/throughput.ts +0 -172
  22. package/assembly/__benches__/vec3.bench.ts +0 -37
  23. package/assembly/__tests__/arbitrary.spec.ts +0 -35
  24. package/assembly/__tests__/array.spec.ts +0 -145
  25. package/assembly/__tests__/bool.spec.ts +0 -12
  26. package/assembly/__tests__/box.spec.ts +0 -27
  27. package/assembly/__tests__/custom.spec.ts +0 -56
  28. package/assembly/__tests__/date.spec.ts +0 -36
  29. package/assembly/__tests__/enum.spec.ts +0 -35
  30. package/assembly/__tests__/float.spec.ts +0 -42
  31. package/assembly/__tests__/generics.spec.ts +0 -49
  32. package/assembly/__tests__/hierarchy.spec.ts +0 -61
  33. package/assembly/__tests__/integer.spec.ts +0 -26
  34. package/assembly/__tests__/lib/index.ts +0 -41
  35. package/assembly/__tests__/map.spec.ts +0 -7
  36. package/assembly/__tests__/namespace.spec.ts +0 -63
  37. package/assembly/__tests__/null.spec.ts +0 -12
  38. package/assembly/__tests__/raw.spec.ts +0 -23
  39. package/assembly/__tests__/resolving.spec.ts +0 -55
  40. package/assembly/__tests__/staticarray.spec.ts +0 -12
  41. package/assembly/__tests__/string.spec.ts +0 -30
  42. package/assembly/__tests__/struct.spec.ts +0 -163
  43. package/assembly/__tests__/test.spec.ts +0 -3
  44. package/assembly/__tests__/types.spec.ts +0 -27
  45. package/assembly/__tests__/types.ts +0 -98
  46. package/assembly/test.tmp.ts +0 -133
  47. package/bench/abc.bench.ts +0 -25
  48. package/bench/large.bench.ts +0 -127
  49. package/bench/lib/bench.d.ts +0 -27
  50. package/bench/lib/bench.js +0 -53
  51. package/bench/lib/chart.ts +0 -217
  52. package/bench/medium.bench.ts +0 -68
  53. package/bench/runners/assemblyscript.js +0 -34
  54. package/bench/small.bench.ts +0 -34
  55. package/bench/throughput.ts +0 -87
  56. package/bench/tsconfig.json +0 -13
  57. package/bench/vec3.bench.ts +0 -30
  58. package/bench.ts +0 -18
  59. package/ci/bench/lib/bench.ts +0 -42
  60. package/ci/bench/runners/assemblyscript.js +0 -29
  61. package/ci/run-bench.as.sh +0 -63
  62. package/publish.sh +0 -78
  63. package/run-bench.as.sh +0 -60
  64. package/run-bench.js.sh +0 -36
  65. package/run-tests.sh +0 -51
  66. package/scripts/build-chart01.ts +0 -38
  67. package/scripts/build-chart02.ts +0 -38
  68. package/scripts/build-chart03.ts +0 -139
  69. package/scripts/build-chart05.ts +0 -47
  70. package/scripts/generate-as-class.ts +0 -50
  71. package/scripts/lib/bench-utils.ts +0 -308
  72. package/transform/src/builder.ts +0 -1375
  73. package/transform/src/index.ts +0 -1486
  74. package/transform/src/linkers/alias.ts +0 -58
  75. package/transform/src/linkers/custom.ts +0 -32
  76. package/transform/src/linkers/imports.ts +0 -22
  77. package/transform/src/types.ts +0 -300
  78. package/transform/src/util.ts +0 -128
  79. package/transform/src/visitor.ts +0 -530
@@ -1,238 +0,0 @@
1
- import { JSON } from "..";
2
- import { expect } from "../__tests__/lib";
3
- import { bench, blackbox, dumpToFile } from "./lib/bench";
4
-
5
- @json
6
- class RepoOwner {
7
- public login!: string;
8
- public id!: i32;
9
- public node_id!: string;
10
- public avatar_url!: string;
11
- public gravatar_id!: string;
12
- public url!: string;
13
- public html_url!: string;
14
- public followers_url!: string;
15
- public following_url!: string;
16
- public gists_url!: string;
17
- public starred_url!: string;
18
- public subscriptions_url!: string;
19
- public organizations_url!: string;
20
- public repos_url!: string;
21
- public events_url!: string;
22
- public received_events_url!: string;
23
- public type!: string;
24
- public user_view_type!: string;
25
- public site_admin!: boolean;
26
- }
27
-
28
- @json
29
- class RepoLicense {
30
- public key!: string;
31
- public name!: string;
32
- public spdx_id!: string;
33
- public url!: string | null;
34
- public node_id!: string;
35
- }
36
-
37
- @json
38
- class Repo {
39
- public id!: i32;
40
- public node_id!: string;
41
- public name!: string;
42
- public full_name!: string;
43
- public private!: boolean;
44
- public owner!: RepoOwner;
45
- public html_url!: string;
46
- public description!: string | null;
47
- public fork!: boolean;
48
- public url!: string;
49
- public forks_url!: string;
50
- public keys_url!: string;
51
- public collaborators_url!: string;
52
- public teams_url!: string;
53
- public hooks_url!: string;
54
- public issue_events_url!: string;
55
- public events_url!: string;
56
- public assignees_url!: string;
57
- public branches_url!: string;
58
- public tags_url!: string;
59
- public blobs_url!: string;
60
- public git_tags_url!: string;
61
- public git_refs_url!: string;
62
- public trees_url!: string;
63
- public statuses_url!: string;
64
- public languages_url!: string;
65
- public stargazers_url!: string;
66
- public contributors_url!: string;
67
- public subscribers_url!: string;
68
- public subscription_url!: string;
69
- public commits_url!: string;
70
- public git_commits_url!: string;
71
- public comments_url!: string;
72
- public issue_comment_url!: string;
73
- public contents_url!: string;
74
- public compare_url!: string;
75
- public merges_url!: string;
76
- public archive_url!: string;
77
- public downloads_url!: string;
78
- public issues_url!: string;
79
- public pulls_url!: string;
80
- public milestones_url!: string;
81
- public notifications_url!: string;
82
- public labels_url!: string;
83
- public releases_url!: string;
84
- public deployments_url!: string;
85
- public created_at!: string;
86
- public updated_at!: string;
87
- public pushed_at!: string;
88
- public git_url!: string;
89
- public ssh_url!: string;
90
- public clone_url!: string;
91
- public svn_url!: string;
92
- public homepage!: string | null;
93
- public size!: i32;
94
- public stargazers_count!: i32;
95
- public watchers_count!: i32;
96
- public language!: string | null;
97
- public has_issues!: boolean;
98
- public has_projects!: boolean;
99
- public has_downloads!: boolean;
100
- public has_wiki!: boolean;
101
- public has_pages!: boolean;
102
- public has_discussions!: boolean;
103
- public forks_count!: i32;
104
- public mirror_url!: string | null;
105
- public archived!: boolean;
106
- public disabled!: boolean;
107
- public open_issues_count!: i32;
108
- public license!: RepoLicense | null;
109
- public allow_forking!: boolean;
110
- public is_template!: boolean;
111
- public web_commit_signoff_required!: boolean;
112
- public topics!: string[];
113
- public visibility!: string;
114
- public forks!: i32;
115
- public open_issues!: i32;
116
- public watchers!: i32;
117
- public default_branch!: string;
118
- }
119
-
120
- // Create instances and assign fields directly
121
- const v1 = new Repo();
122
- const owner = new RepoOwner();
123
-
124
- owner.login = "octocat";
125
- owner.id = 583231;
126
- owner.node_id = "MDQ6VXNlcjU4MzIzMQ==";
127
- owner.avatar_url = "https://avatars.githubusercontent.com/u/583231?v=4";
128
- owner.gravatar_id = "";
129
- owner.url = "https://api.github.com/users/octocat";
130
- owner.html_url = "https://github.com/octocat";
131
- owner.followers_url = "https://api.github.com/users/octocat/followers";
132
- owner.following_url = "https://api.github.com/users/octocat/following{/other_user}";
133
- owner.gists_url = "https://api.github.com/users/octocat/gists{/gist_id}";
134
- owner.starred_url = "https://api.github.com/users/octocat/starred{/owner}{/repo}";
135
- owner.subscriptions_url = "https://api.github.com/users/octocat/subscriptions";
136
- owner.organizations_url = "https://api.github.com/users/octocat/orgs";
137
- owner.repos_url = "https://api.github.com/users/octocat/repos";
138
- owner.events_url = "https://api.github.com/users/octocat/events{/privacy}";
139
- owner.received_events_url = "https://api.github.com/users/octocat/received_events";
140
- owner.type = "User";
141
- owner.user_view_type = "public";
142
- owner.site_admin = false;
143
-
144
- v1.owner = owner;
145
-
146
- v1.id = 132935648;
147
- v1.node_id = "MDEwOlJlcG9zaXRvcnkxMzI5MzU2NDg=";
148
- v1.name = "boysenberry-repo-1";
149
- v1.full_name = "octocat/boysenberry-repo-1";
150
- v1.private = true;
151
- v1.html_url = "https://github.com/octocat/boysenberry-repo-1";
152
- v1.description = "Testing";
153
- v1.fork = true;
154
- v1.url = "https://api.github.com/repos/octocat/boysenberry-repo-1";
155
- v1.forks_url = "https://api.github.com/repos/octocat/boysenberry-repo-1/forks";
156
- v1.keys_url = "https://api.github.com/repos/octocat/boysenberry-repo-1/keys{/key_id}";
157
- v1.collaborators_url = "https://api.github.com/repos/octocat/boysenberry-repo-1/collaborators{/collaborator}";
158
- v1.teams_url = "https://api.github.com/repos/octocat/boysenberry-repo-1/teams";
159
- v1.hooks_url = "https://api.github.com/repos/octocat/boysenberry-repo-1/hooks";
160
- v1.issue_events_url = "https://api.github.com/repos/octocat/boysenberry-repo-1/issues/events{/number}";
161
- v1.events_url = "https://api.github.com/repos/octocat/boysenberry-repo-1/events";
162
- v1.assignees_url = "https://api.github.com/repos/octocat/boysenberry-repo-1/assignees{/user}";
163
- v1.branches_url = "https://api.github.com/repos/octocat/boysenberry-repo-1/branches{/branch}";
164
- v1.tags_url = "https://api.github.com/repos/octocat/boysenberry-repo-1/tags";
165
- v1.blobs_url = "https://api.github.com/repos/octocat/boysenberry-repo-1/git/blobs{/sha}";
166
- v1.git_tags_url = "https://api.github.com/repos/octocat/boysenberry-repo-1/git/tags{/sha}";
167
- v1.git_refs_url = "https://api.github.com/repos/octocat/boysenberry-repo-1/git/refs{/sha}";
168
- v1.trees_url = "https://api.github.com/repos/octocat/boysenberry-repo-1/git/trees{/sha}";
169
- v1.statuses_url = "https://api.github.com/repos/octocat/boysenberry-repo-1/statuses/{sha}";
170
- v1.languages_url = "https://api.github.com/repos/octocat/boysenberry-repo-1/languages";
171
- v1.stargazers_url = "https://api.github.com/repos/octocat/boysenberry-repo-1/stargazers";
172
- v1.contributors_url = "https://api.github.com/repos/octocat/boysenberry-repo-1/contributors";
173
- v1.subscribers_url = "https://api.github.com/repos/octocat/boysenberry-repo-1/subscribers";
174
- v1.subscription_url = "https://api.github.com/repos/octocat/boysenberry-repo-1/subscription";
175
- v1.commits_url = "https://api.github.com/repos/octocat/boysenberry-repo-1/commits{/sha}";
176
- v1.git_commits_url = "https://api.github.com/repos/octocat/boysenberry-repo-1/git/commits{/sha}";
177
- v1.comments_url = "https://api.github.com/repos/octocat/boysenberry-repo-1/comments{/number}";
178
- v1.issue_comment_url = "https://api.github.com/repos/octocat/boysenberry-repo-1/issues/comments{/number}";
179
- v1.contents_url = "https://api.github.com/repos/octocat/boysenberry-repo-1/contents/{+path}";
180
- v1.compare_url = "https://api.github.com/repos/octocat/boysenberry-repo-1/compare/{base}...{head}";
181
- v1.merges_url = "https://api.github.com/repos/octocat/boysenberry-repo-1/merges";
182
- v1.archive_url = "https://api.github.com/repos/octocat/boysenberry-repo-1/{archive_format}{/ref}";
183
- v1.downloads_url = "https://api.github.com/repos/octocat/boysenberry-repo-1/downloads";
184
- v1.issues_url = "https://api.github.com/repos/octocat/boysenberry-repo-1/issues{/number}";
185
- v1.pulls_url = "https://api.github.com/repos/octocat/boysenberry-repo-1/pulls{/number}";
186
- v1.milestones_url = "https://api.github.com/repos/octocat/boysenberry-repo-1/milestones{/number}";
187
- v1.notifications_url = "https://api.github.com/repos/octocat/boysenberry-repo-1/notifications{?since,all,participating}";
188
- v1.labels_url = "https://api.github.com/repos/octocat/boysenberry-repo-1/labels{/name}";
189
- v1.releases_url = "https://api.github.com/repos/octocat/boysenberry-repo-1/releases{/id}";
190
- v1.deployments_url = "https://api.github.com/repos/octocat/boysenberry-repo-1/deployments";
191
- v1.created_at = "2018-05-10T17:51:29Z";
192
- v1.updated_at = "2025-05-24T02:01:19Z";
193
- v1.pushed_at = "2024-05-26T07:02:05Z";
194
- v1.git_url = "git://github.com/octocat/boysenberry-repo-1.git";
195
- v1.ssh_url = "git@github.com:octocat/boysenberry-repo-1.git";
196
- v1.clone_url = "https://github.com/octocat/boysenberry-repo-1.git";
197
- v1.svn_url = "https://github.com/octocat/boysenberry-repo-1";
198
- v1.homepage = "";
199
- v1.size = 4;
200
- v1.stargazers_count = 332;
201
- v1.watchers_count = 332;
202
- v1.language = null;
203
- v1.has_issues = false;
204
- v1.has_projects = true;
205
- v1.has_downloads = true;
206
- v1.has_wiki = true;
207
- v1.has_pages = false;
208
- v1.has_discussions = false;
209
- v1.forks_count = 20;
210
- v1.mirror_url = null;
211
- v1.archived = false;
212
- v1.disabled = false;
213
- v1.open_issues_count = 1;
214
- v1.license = null;
215
- v1.allow_forking = true;
216
- v1.is_template = false;
217
- v1.web_commit_signoff_required = false;
218
- v1.topics = [];
219
- v1.visibility = "public";
220
- v1.forks = 20;
221
- v1.open_issues = 1;
222
- v1.watchers = 332;
223
- v1.default_branch = "master";
224
-
225
- const v2 = `{"id":132935648,"node_id":"MDEwOlJlcG9zaXRvcnkxMzI5MzU2NDg=","name":"boysenberry-repo-1","full_name":"octocat/boysenberry-repo-1","private":true,"owner":{"login":"octocat","id":583231,"node_id":"MDQ6VXNlcjU4MzIzMQ==","avatar_url":"https://avatars.githubusercontent.com/u/583231?v=4","gravatar_id":"","url":"https://api.github.com/users/octocat","html_url":"https://github.com/octocat","followers_url":"https://api.github.com/users/octocat/followers","following_url":"https://api.github.com/users/octocat/following{/other_user}","gists_url":"https://api.github.com/users/octocat/gists{/gist_id}","starred_url":"https://api.github.com/users/octocat/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/octocat/subscriptions","organizations_url":"https://api.github.com/users/octocat/orgs","repos_url":"https://api.github.com/users/octocat/repos","events_url":"https://api.github.com/users/octocat/events{/privacy}","received_events_url":"https://api.github.com/users/octocat/received_events","type":"User","user_view_type":"public","site_admin":false},"html_url":"https://github.com/octocat/boysenberry-repo-1","description":"Testing","fork":true,"url":"https://api.github.com/repos/octocat/boysenberry-repo-1","forks_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/forks","keys_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/keys{/key_id}","collaborators_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/teams","hooks_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/hooks","issue_events_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/issues/events{/number}","events_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/events","assignees_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/assignees{/user}","branches_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/branches{/branch}","tags_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/tags","blobs_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/git/refs{/sha}","trees_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/git/trees{/sha}","statuses_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/statuses/{sha}","languages_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/languages","stargazers_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/stargazers","contributors_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/contributors","subscribers_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/subscribers","subscription_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/subscription","commits_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/commits{/sha}","git_commits_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/git/commits{/sha}","comments_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/comments{/number}","issue_comment_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/issues/comments{/number}","contents_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/contents/{+path}","compare_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/compare/{base}...{head}","merges_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/merges","archive_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/downloads","issues_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/issues{/number}","pulls_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/pulls{/number}","milestones_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/milestones{/number}","notifications_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/labels{/name}","releases_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/releases{/id}","deployments_url":"https://api.github.com/repos/octocat/boysenberry-repo-1/deployments","created_at":"2018-05-10T17:51:29Z","updated_at":"2025-05-24T02:01:19Z","pushed_at":"2024-05-26T07:02:05Z","git_url":"git://github.com/octocat/boysenberry-repo-1.git","ssh_url":"git@github.com:octocat/boysenberry-repo-1.git","clone_url":"https://github.com/octocat/boysenberry-repo-1.git","svn_url":"https://github.com/octocat/boysenberry-repo-1","homepage":"","size":4,"stargazers_count":332,"watchers_count":332,"language":null,"has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"has_discussions":false,"forks_count":20,"mirror_url":null,"archived":false,"disabled":false,"open_issues_count":1,"license":null,"allow_forking":true,"is_template":false,"web_commit_signoff_required":false,"topics":[],"visibility":"public","forks":20,"open_issues":1,"watchers":332,"default_branch":"master"}`;
226
-
227
- expect(JSON.stringify(v1)).toBe(v2);
228
- expect(JSON.stringify(JSON.parse<Repo>(v2))).toBe(v2);
229
-
230
- bench("Serialize Large API Response", () => {
231
- blackbox(inline.always(JSON.stringify(v1)));
232
- }, 10_000, 10502);
233
- dumpToFile("large", "serialize")
234
-
235
- bench("Deserialize Large API Response", () => {
236
- blackbox(inline.always(JSON.parse<Repo>(v2)));
237
- }, 10_000, 10502);
238
- dumpToFile("large", "deserialize")
@@ -1,85 +0,0 @@
1
- import { JSON } from "../..";
2
- // @ts-ignore: decorator allowed
3
- @external("env", "writeFile")
4
- declare function writeFile(fileName: string, data: string): void;
5
-
6
- @json
7
- class BenchResult {
8
- language: string = "assemblyscript";
9
- description!: string;
10
- elapsed!: f64;
11
- bytes!: u64;
12
- operations!: u64;
13
- features!: string[];
14
- mbps!: f64;
15
- gbps!: f64;
16
- }
17
-
18
- let result: BenchResult | null = null;
19
- export function bench(description: string, routine: () => void, ops: u64 = 1_000_000, bytesPerOp: u64 = 0): void {
20
- console.log(" - Benchmarking " + description);
21
-
22
- let warmup = ops / 10;
23
- while (--warmup) {
24
- routine();
25
- }
26
-
27
- const start = performance.now();
28
-
29
- let count = ops;
30
- while (count--) {
31
- routine();
32
- }
33
-
34
- const end = performance.now();
35
- const elapsed = Math.max(1, end - start);
36
-
37
- const opsPerSecond = f64(ops * 1000) / elapsed;
38
-
39
- let log = ` Completed benchmark in ${formatNumber(u64(Math.round(elapsed)))}ms at ${formatNumber(u64(Math.round(opsPerSecond)))} ops/s`;
40
-
41
- let mbPerSec: f64 = 0;
42
- if (bytesPerOp > 0) {
43
- const totalBytes = bytesPerOp * ops;
44
- mbPerSec = f64(totalBytes) / (elapsed / 1000) / (1000 * 1000);
45
- log += ` @ ${formatNumber(u64(Math.round(mbPerSec)))}MB/s`;
46
- }
47
-
48
- const features: string[] = [];
49
- if (ASC_FEATURE_SIMD) features.push("simd");
50
-
51
- result = {
52
- language: "assemblycript",
53
- description,
54
- elapsed,
55
- bytes: bytesPerOp,
56
- operations: ops,
57
- features,
58
- mbps: mbPerSec,
59
- gbps: mbPerSec / 1000
60
- }
61
-
62
- console.log(log + "\n");
63
- }
64
-
65
- export function dumpToFile(suite: string, type: string): void {
66
- writeFile("./build/logs/as/"+ (ASC_FEATURE_SIMD ? "simd/" : "swar/") + suite+"."+type+".as.json", JSON.stringify(result));
67
- }
68
-
69
- function formatNumber(n: u64): string {
70
- let str = n.toString();
71
- let len = str.length;
72
- let result = "";
73
- let commaOffset = len % 3;
74
- for (let i = 0; i < len; i++) {
75
- if (i > 0 && (i - commaOffset) % 3 == 0) result += ",";
76
- result += str.charAt(i);
77
- }
78
- return result;
79
- }
80
-
81
- const blackBoxArea = memory.data(64);
82
- export function blackbox<T>(value: T): T {
83
- store<T>(blackBoxArea, value);
84
- return load<T>(blackBoxArea);
85
- }
@@ -1,128 +0,0 @@
1
- import { JSON } from "..";
2
- import { expect } from "../__tests__/lib";
3
- import { bench, blackbox, dumpToFile } from "./lib/bench";
4
-
5
- @json
6
- class UserPreferences {
7
- theme!: string;
8
- notifications!: boolean;
9
- language!: string;
10
- timezone!: string;
11
- privacy_level!: string;
12
- two_factor_enabled!: boolean;
13
- }
14
-
15
- @json
16
- class RecentActivity {
17
- action!: string;
18
- timestamp!: string;
19
- target!: string;
20
- }
21
-
22
- @json
23
- class MediumAPIResponse {
24
- id!: i32;
25
- username!: string;
26
- full_name!: string;
27
- email!: string;
28
- avatar_url!: string;
29
- bio!: string;
30
- website!: string;
31
- location!: string;
32
- joined_at!: string;
33
- is_verified!: boolean;
34
- is_premium!: boolean;
35
- follower_count!: i32;
36
- following_count!: i32;
37
-
38
- preferences!: UserPreferences;
39
- tags!: string[];
40
-
41
- recent_activity!: RecentActivity[];
42
- }
43
-
44
- const v1 = new MediumAPIResponse();
45
- const prefs = new UserPreferences();
46
-
47
- prefs.theme = "dark";
48
- prefs.notifications = true;
49
- prefs.language = "en-US";
50
- prefs.timezone = "America/Los_Angeles";
51
- prefs.privacy_level = "friends_only";
52
- prefs.two_factor_enabled = false;
53
-
54
- v1.id = 42;
55
- v1.username = "jairus";
56
- v1.full_name = "Jairus Tanaka";
57
- v1.email = "me@jairus.dev";
58
- v1.avatar_url = "https://avatars.githubusercontent.com/u/123456?v=4";
59
- v1.bio = "I like compilers, elegant algorithms, bare metal, simd, and wasm.";
60
- v1.website = "https://jairus.dev/";
61
- v1.location = "Seattle, WA";
62
- v1.joined_at = "2020-01-15T08:30:00Z";
63
- v1.is_verified = true;
64
- v1.is_premium = true;
65
- v1.follower_count = 61;
66
- v1.following_count = 39;
67
-
68
- v1.preferences = prefs;
69
-
70
- v1.tags = ["typescript", "webassembly", "performance", "rust", "assemblyscript", "json"];
71
-
72
- v1.recent_activity = new Array<RecentActivity>(5);
73
-
74
- let act0 = new RecentActivity();
75
- act0.action = "starred";
76
- act0.timestamp = "2025-12-22T10:15:00Z";
77
- act0.target = "assemblyscript/json-as";
78
- v1.recent_activity[0] = act0;
79
-
80
- let act1 = new RecentActivity();
81
- act1.action = "commented";
82
- act1.timestamp = "2025-12-22T09:42:00Z";
83
- act1.target = "issue #142";
84
- v1.recent_activity[1] = act1;
85
-
86
- let act2 = new RecentActivity();
87
- act2.action = "pushed";
88
- act2.timestamp = "2025-12-21T23:58:00Z";
89
- act2.target = "main branch";
90
- v1.recent_activity[2] = act2;
91
-
92
- let act3 = new RecentActivity();
93
- act3.action = "forked";
94
- act3.timestamp = "2025-12-21T18:20:00Z";
95
- act3.target = "fast-json-wasm";
96
- v1.recent_activity[3] = act3;
97
-
98
- let act4 = new RecentActivity();
99
- act4.action = "created";
100
- act4.timestamp = "2025-12-21T14:10:00Z";
101
- act4.target = "new benchmark suite";
102
- v1.recent_activity[4] = act4;
103
-
104
- const v2: string = JSON.stringify<MediumAPIResponse>(v1);
105
- const byteLength: usize = v2.length << 1;
106
-
107
- expect(JSON.stringify(v1)).toBe(v2);
108
- expect(JSON.stringify(JSON.parse<MediumAPIResponse>(v2))).toBe(v2);
109
-
110
- bench(
111
- "Serialize Medium API Response",
112
- () => {
113
- blackbox(inline.always(JSON.stringify<MediumAPIResponse>(v1)));
114
- },
115
- 500_000,
116
- byteLength
117
- );
118
- dumpToFile("medium", "serialize")
119
-
120
- bench(
121
- "Deserialize Medium API Response",
122
- () => {
123
- blackbox(inline.always(JSON.parse<MediumAPIResponse>(v2)));
124
- },
125
- 500_000,
126
- byteLength
127
- );
128
- dumpToFile("medium", "deserialize")
@@ -1,46 +0,0 @@
1
- import { JSON } from "..";
2
- import { expect } from "../__tests__/lib";
3
- import { bench, blackbox, dumpToFile } from "./lib/bench";
4
-
5
- @json
6
- class SessionStatusResponse {
7
- authenticated!: boolean;
8
- user_id!: i32;
9
- username!: string;
10
- role!: string;
11
- expires_at!: string;
12
- }
13
-
14
- const v1 = new SessionStatusResponse();
15
-
16
- v1.authenticated = true;
17
- v1.user_id = 8472;
18
- v1.username = "jairus";
19
- v1.role = "admin";
20
- v1.expires_at = "2025-12-23T04:30:00Z";
21
-
22
- const v2: string = JSON.stringify<SessionStatusResponse>(v1);
23
- const byteLength: usize = v2.length << 1;
24
-
25
- expect(JSON.stringify(v1)).toBe(v2);
26
- expect(JSON.stringify(JSON.parse<SessionStatusResponse>(v2))).toBe(v2);
27
-
28
- bench(
29
- "Serialize Small API Response",
30
- () => {
31
- blackbox(inline.always(JSON.stringify<SessionStatusResponse>(v1)));
32
- },
33
- 5_000_000,
34
- byteLength
35
- );
36
- dumpToFile("small", "serialize")
37
-
38
- bench(
39
- "Deserialize Small API Response",
40
- () => {
41
- blackbox(inline.always(JSON.parse<SessionStatusResponse>(v2)));
42
- },
43
- 5_000_000,
44
- byteLength
45
- );
46
- dumpToFile("small", "deserialize")