Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hexagon/primer
Benchmark of prime number calculation on pure javascript vs. wasm
https://github.com/hexagon/primer
bun nodejs
Last synced: 17 days ago
JSON representation
Benchmark of prime number calculation on pure javascript vs. wasm
- Host: GitHub
- URL: https://github.com/hexagon/primer
- Owner: Hexagon
- License: mit
- Created: 2022-10-17T18:54:50.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2023-09-17T18:15:19.000Z (over 1 year ago)
- Last Synced: 2024-10-30T09:04:27.113Z (about 2 months ago)
- Topics: bun, nodejs
- Language: JavaScript
- Homepage:
- Size: 178 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## primer
Benchmarking project showing prime number calculation on pure JavaScript vs. WASM in Node, Deno and Bun.
### Running
No special tools required. Just make sure the runtime you want to benchmark is installed, or simply open this repository in a GitHub Codespace - both Deno and Node will be pre-installed and ready to run.
If you want to use bun in a devcontainer, follow the instructions at [https://bun.sh/](bun.sh).
#### Deno
1. Install a recent version of Deno, see [https://deno.land/#installation](https://deno.land/#installation) - or use CodeSpaces.
2. Run using command ```deno task bench```#### Node
1. Install a recent version of Node - or use CodeSpaces.
2. Install dependencies ```npm install```
2. Run using command ```npm run bench```#### Bun
1. Install a recent version of Bun, see [https://bun.sh/](https://bun.sh/).
2. Install dependencies ```bun install```
2. Run using command ```bun run bench:bun```#### Full benchmark
1. Make sure all runtimes listed above is installed
2. Run using command ```deno task bench:all```### Contributing
To add a new prime calculation implementation
1. Add new folder `implementations/`
2. Add `index.js` which is the implementation entrypoint, index.js should export name (string), type (string), description (string) and checkPrime (function)
3. **WASM only:** If adding a wasm implementation, also add a new build task in `deno.jsonc` which is set up to generate the `.wasm`
4. **WASM only:** Build your module by running ```deno task build-```
5. Make sure your implementation pass all tests by running ```deno task test```See `implementations/simplejs` or `implementations/aswasm` for examples.
#### WASM prerequisites
I recommend AssembyScript for compiling WASM, as installing it is a oneliner if you already have Node.
Alternative toolchains for building wasm modules include Rust or Emscriptem.
### Folder structure
.
├── implementations
│ ├── # One folder for each implementation, containg:
│ │ ├── README.md # Implementation README
│ │ ├── index.js # implementation entrypoint (mandatory)
│ │ └── ... # (Implementation specific files and folders)
│ └── ... # More implementations
│
├── common # Cross platform helper javascript
│ └── filereader.js # Cross platform file reader
│
├── deno, node, ...? # One folder per runtime environment
│ ├── bench.js # Runtime specific benchmark runnner
│ ├── tests.js # Runtime specific implementation tests
│ └── importer.js # Runtime specific helper to automatically import all implementations
│
├── deno.jsonc # Deno task configuration
├── package.json # Node task configuration
└── ...