Skip to content

Instantly share code, notes, and snippets.

@adorsk
Last active January 17, 2021 21:40
Show Gist options
  • Save adorsk/3011ceb830a73d138fcc48f2e57775ad to your computer and use it in GitHub Desktop.
Save adorsk/3011ceb830a73d138fcc48f2e57775ad to your computer and use it in GitHub Desktop.
const { performance } = require('perf_hooks')
const contestants = [
{
key: 'main',
getCtx () {
return {
Automerge: require('./scratch/automerge-main/src/automerge'),
}
},
},
{
key: 'performance',
getCtx () {
return {
Automerge: require('./scratch/automerge-performance/src/automerge'),
}
},
},
{
key: 'rust',
getCtx () {
delete require.cache[require.resolve('./scratch/automerge-performance/src/automerge')]
const Automerge = require('./scratch/automerge-performance/src/automerge')
const wasmBackend = require('./scratch/automerge-rs/automerge-backend-wasm')
Automerge.setDefaultBackend(wasmBackend)
return { Automerge }
},
},
]
for (const contestant of contestants) {
const ctx = contestant.getCtx()
const Automerge = ctx.Automerge
const start = performance.now()
const numRuns = 1e3
for (let i = 0; i < numRuns; i++) {
const doc1 = Automerge.from({
stringValue: 'string',
arrayValue: [0, 1],
mapValue: { a: 'a', b: 'b' }
})
const doc2 = Automerge.change(doc1, (doc) => {
doc.stringValue = 'string:new'
doc.arrayValue.splice(1, 1, 2, 3)
doc.mapValue.dessert = 'ice cream'
delete doc.mapValue.flavor
doc.mapValue.topping = 'hot fudge'
})
}
const end = performance.now()
const report = {
key: contestant.key,
time: (end - start) / numRuns,
}
console.log(JSON.stringify(report, null, 2))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment