pa x 630 ops/sec ±1.74% (76 runs sampled)
pb x 7.28 ops/sec ±1.36% (38 runs sampled)
let Benchmark = require('benchmark')
let suite = new Benchmark.Suite()
pa x 630 ops/sec ±1.74% (76 runs sampled)
pb x 7.28 ops/sec ±1.36% (38 runs sampled)
let Benchmark = require('benchmark')
let suite = new Benchmark.Suite()
The reason your tests is junk is because you are accidentally introducing all kinds of other variables into the environment (just like your other test, when you reverse it, it favors then-ables), too many side effects. Let the framework handle cycles, that's part of its purpose. Also, the end goal isn't for then-ables to out-perform promises, it's just to demonstrate a neat alternative way to create things that can be awaited.
To placate your placation, here is the same test with less noise...
p x 0.86 ops/sec ±0.31% (9 runs sampled)
t x 0.86 ops/sec ±0.16% (9 runs sampled)
function mkPromise(k) {
return new Promise(resolve => setTimeout(() => resolve(k), 1))
}
function mkThenable(k) {
return {
then(done) { setTimeout(() => done(k), 1) }
};
}
const Benchmark = require('benchmark') | |
const suite = new Benchmark.Suite() | |
suite.on('cycle', event => console.log(String(event.target))) | |
const add = (name, fn) => suite.add(name, fn, { defer: true }) | |
add('p', complete => { | |
async function test () { | |
const p = new Promise((resolve, reject) => { |
async function main () { | |
const p = await fetch('https://api.github.com/users/zeke') | |
const j = await p.json() | |
console.log(j) | |
document.body.innerHTML = ` | |
<style> | |
body { | |
padding: 20px 10px; |
// | |
// CSS | |
// | |
const style = ` | |
* { box-sizing: border-box; } | |
body { margin: 0 } | |
canvas { | |
width: 100%; | |
height: 100%; |
I hereby claim:
To claim this, I am signing this object:
# | |
# After installing Node.js, Get the SDK | |
# | |
curl https://s3.amazonaws.com/mozilla-games/emscripten/releases/emsdk-portable.tar.gz ~/Downloads/emsdk-portable.tar.gz | |
tar -xzf ~/Downloads/emsdk-portable.tar.gz ~/emscripten | |
cd ~/emscripten | |
# | |
# Fetch the latest registry of available tools. | |
# |
foo: { | |
const { err, res } = await request('https://quxx.ht') | |
if (err) { | |
// handle error | |
break foo | |
} | |
// handle success | |
} |
// | |
// target.on(type, listener[, options]) | |
// | |
EventTarget.prototype.on = EventTarget.prototype.addEventListener | |
// | |
// target.once(type, listener[, options]) | |
// | |
EventTarget.prototype.once = function (type, listener, options = {}) { |