Skip to content
/ primer Public

Benchmark of prime number calculation on pure javascript vs. wasm

License

Notifications You must be signed in to change notification settings

Hexagon/primer

Repository files navigation

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/.

Deno

  1. Install a recent version of Deno, see 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
  3. Run using command npm run bench

Bun

  1. Install a recent version of Bun, see https://bun.sh/.
  2. Install dependencies bun install
  3. 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/<name of implementation>
  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-<name of implementation>
  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             
│   ├── <implementation-name>   # 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
└── ...

About

Benchmark of prime number calculation on pure javascript vs. wasm

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published