Skip to content

Commit

Permalink
update AS. Remove rabin-native due to problem rebuilding
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxGraey committed Jan 1, 2020
1 parent c63a722 commit 10455fd
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 24 deletions.
22 changes: 11 additions & 11 deletions benchmarks/node.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
const Benchmark = require('benchmark')
const Rabin = require('rabin')
// const Rabin = require('rabin')
const RabinWasm = require('../cli/rabin-stream')
const RabinJs = require('./rabin-pure')
const randomStream = require('iso-random-stream')
const suite = new Benchmark.Suite();

// add tests
suite
.add('native rabin', {
defer: true,
fn(deferred) {
const rabin = new Rabin()
const data = randomStream(100 * 1000 * 1024)
data.pipe(rabin)
rabin.on('data', () => {})
rabin.on('end', () => deferred.resolve())
}
})
// .add('native rabin', {
// defer: true,
// fn(deferred) {
// const rabin = new Rabin()
// const data = randomStream(100 * 1000 * 1024)
// data.pipe(rabin)
// rabin.on('data', () => {})
// rabin.on('end', () => deferred.resolve())
// }
// })
.add('wasm rabin', {
defer: true,
fn(deferred) {
Expand Down
4 changes: 2 additions & 2 deletions cli/rabin-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ const util = require('util')
const BufferList = require('bl')
const debug = require('debug')('rabin')

const { instantiateBuffer } = require("assemblyscript/lib/loader");
const compiled = instantiateBuffer(fs.readFileSync(__dirname + "/../dist/rabin.wasm"), {});
const { instantiateSync } = require("@assemblyscript/loader");
const compiled = instantiateSync(fs.readFileSync(__dirname + "/../dist/rabin.wasm"), {});

module.exports = RabinStream

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"url": "git+https://github.com/hugomrdias/rabin-wasm.git"
},
"dependencies": {
"assemblyscript": "AssemblyScript/assemblyscript",
"@assemblyscript/loader": "^0.8.1-nightly.20200101",
"bl": "^4.0.0",
"debug": "^4.1.1",
"minimist": "^1.2.0",
Expand All @@ -41,12 +41,12 @@
},
"devDependencies": {
"@as-pect/cli": "^2.5.0",
"assemblyscript": "^0.8.1-nightly.20200101",
"benchmark": "^2.1.4",
"browserify": "^16.3.0",
"iso-random-stream": "^1.1.0",
"long": "^4.0.0",
"np": "^5.1.1",
"rabin": "^2.0.0",
"size-limit": "^2.1.6"
}
}
8 changes: 4 additions & 4 deletions tools/wasm2js.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
module.exports = function wasm2js(wasmBuf) {

return `
const { instantiateStreaming } = require("assemblyscript/lib/loader");
const { instantiateStreaming } = require("@assemblyscript/loader");
loadWebAssembly.supported = typeof WebAssembly !== 'undefined'
function loadWebAssembly (imp = {}) {
if (!loadWebAssembly.supported) return null
var wasm = new Uint8Array([${wasmBuf.join(',')}])
// make it work async because browsers throw when a wasm module is bigger than 4kb and load sync
return instantiateStreaming(new Response(new Blob([wasm], {type: 'application/wasm'})), imp)
Expand Down
10 changes: 5 additions & 5 deletions tools/wasm2js.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
module.exports = function wasm2js(wasmBuf) {

return `
const { instantiateBuffer } = require("assemblyscript/lib/loader");
const { instantiateSync } = require("@assemblyscript/loader");
const fs = require('fs')
loadWebAssembly.supported = typeof WebAssembly !== 'undefined'
async function loadWebAssembly (imp = {}) {
if (!loadWebAssembly.supported) return null
return instantiateBuffer(fs.readFileSync(__dirname + "/../dist/rabin.wasm"), imp);
return instantiateSync(fs.readFileSync(__dirname + "/../dist/rabin.wasm"), imp);
}
module.exports = loadWebAssembly
`.replace(/^ {4}/gm, '')
Expand Down

0 comments on commit 10455fd

Please sign in to comment.