Write Program
Write
In AssemblyScript, Sieve of Eratosthenes can be written as
assemblyscript/assembly/prime.ts
loading...
Build for Test
Build AssemblyScript to 'Glue JavaScript' and WebAssembly.
asc
command is used here to build which is installed by assemblyscript.
build with asc command
asc assembly/prime.ts --target release
Other asc command options can be found at Using the compiler.
Or, you can use npm
.
asbuild:release
which runs the same command above defined in package.json
.
build with npm command
npm run asbuild:release
This generates glue JavaScript and wasm.
- prime.wasm
- prime.js
Run and Test
Now, run the test written in tests/index.js
.
run tests
node tests
or, alternatively
run tests
npm run test
The test would show
output
(Use `node --trace-warnings ...` to show where the warning was created)
test ok
max prime = 9973
duration [ms] = 2.88
The following table shows the calculated prime for given "N".
given N | prime |
---|---|
2 | 2 |
3 | 3 |
10 | 7 |
100 | 97 |
1000 | 997 |
10000 | 9973 |
100000 | 99991 |