-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support jstype custom options (#117)
Allow overriding 64 bit number types with strings or regular js numbers. Closes #112
- Loading branch information
1 parent
d5bf315
commit ba35475
Showing
23 changed files
with
853 additions
and
44 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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,15 @@ | ||
/* eslint-disable no-console */ | ||
|
||
/* | ||
$ node dist/src/numbers/index.js | ||
$ npx playwright-test dist/src/numbers/index.js --runner benchmark | ||
*/ | ||
|
||
import { readBenchmark } from './read.js' | ||
import { writeBenchmark } from './write.js' | ||
|
||
console.info('-- read --') | ||
await readBenchmark() | ||
|
||
console.info('-- write --') | ||
await writeBenchmark() |
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,42 @@ | ||
/* eslint-disable no-console */ | ||
|
||
import Benchmark from 'benchmark' | ||
import { writer, reader } from 'protons-runtime' | ||
|
||
const bigint = 100n | ||
|
||
const w = writer() | ||
w.uint64(bigint) | ||
|
||
const buf = w.finish() | ||
|
||
export async function readBenchmark (): Promise<void> { | ||
return new Promise<void>((resolve) => { | ||
new Benchmark.Suite() | ||
.add('uint64 (BigInt)', () => { | ||
const r = reader(buf) | ||
r.uint64() | ||
}) | ||
.add('uint64number', () => { | ||
const r = reader(buf) | ||
r.uint64Number() | ||
}) | ||
.add('uint64string', () => { | ||
const r = reader(buf) | ||
r.uint64String() | ||
}) | ||
.on('error', (err: Error) => { | ||
console.error(err) | ||
}) | ||
.on('cycle', (event: any) => { | ||
console.info(String(event.target)) | ||
}) | ||
.on('complete', function () { | ||
// @ts-expect-error types are wrong | ||
console.info(`Fastest is ${this.filter('fastest').map('name')}`) | ||
resolve() | ||
}) | ||
// run async | ||
.run({ async: true }) | ||
}) | ||
} |
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,39 @@ | ||
/* eslint-disable no-console */ | ||
|
||
import Benchmark from 'benchmark' | ||
import { writer } from 'protons-runtime' | ||
|
||
const number = 100 | ||
const bigint = 100n | ||
const string = '100' | ||
|
||
export async function writeBenchmark (): Promise<void> { | ||
return new Promise<void>((resolve) => { | ||
new Benchmark.Suite() | ||
.add('uint64 (BigInt)', () => { | ||
const w = writer() | ||
w.uint64(bigint) | ||
}) | ||
.add('uint64number', () => { | ||
const w = writer() | ||
w.uint64Number(number) | ||
}) | ||
.add('uint64string', () => { | ||
const w = writer() | ||
w.uint64String(string) | ||
}) | ||
.on('error', (err: Error) => { | ||
console.error(err) | ||
}) | ||
.on('cycle', (event: any) => { | ||
console.info(String(event.target)) | ||
}) | ||
.on('complete', function () { | ||
// @ts-expect-error types are wrong | ||
console.info(`Fastest is ${this.filter('fastest').map('name')}`) | ||
resolve() | ||
}) | ||
// run async | ||
.run({ async: true }) | ||
}) | ||
} |
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
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
Oops, something went wrong.