Skip to content

Commit

Permalink
better benchmark with literl object too
Browse files Browse the repository at this point in the history
  • Loading branch information
WebReflection committed Feb 27, 2021
1 parent b50268a commit fa1ce95
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
6 changes: 3 additions & 3 deletions README.md
Expand Up @@ -83,11 +83,11 @@ Following an `hermes -jit test/benchmark.js` run, using `0xFFF` iterations over

| |Fake Class |Babel Class|Hermes Class|Hermes Class + super|
|-----------|-----------|-----------|------------|--------------------|
|creation | 493ms | 797ms | 378ms | 363ms |
|add(1) | 54ms | 71ms | 68ms | 953ms |
|creation | 493ms | 797ms | 343ms | 363ms |
|add(1) | 54ms | 71ms | 42ms | 893ms |
|has(1) | 55ms | 92ms | 53ms | 73ms |
|size | 63ms | 43ms | 30ms | 34ms |
|@@iterate | 920ms | 443ms | 416ms | 400ms |
|@@iterate | 920ms | 443ms | 396ms | 368ms |



Expand Down
Binary file modified benchmark.hbc
Binary file not shown.
28 changes: 25 additions & 3 deletions test/benchmark.js
Expand Up @@ -378,6 +378,27 @@ Object.defineProperties(FakeClass.prototype, {
}}
});

function Literal(...args) {
const _ = new Set(...args);
return {
__proto__: Set.prototype,
add() {
for (let i = 0; i < arguments.length; i++)
_.add(arguments[i]);
return this;
},
has(value) {
return _.has(value);
},
get size() {
return _.size;
},
get [Symbol.iterator]() {
return _[Symbol.iterator].bind(_);
}
};
}

function benchmark(name, Class, times = hermes ? 0xFFF : 0xFFFF) {
return new globalThis.Promise((resolve, reject) => {
log(`\x1b[1m${name}\x1b[0m`);
Expand Down Expand Up @@ -420,7 +441,7 @@ function benchmark(name, Class, times = hermes ? 0xFFF : 0xFFFF) {
date = new Date - date;
log(` @@iterate: ${date}ms`);
log('');
resolve();
globalThis.setTimeout(resolve, 500);
});
}

Expand All @@ -439,8 +460,9 @@ globalThis.Promise.resolve()
}
catch (meh) {}
})
.then(() => benchmark(' Fake Class', FakeClass))
.then(() => benchmark(' Babel Class', BabelSet))
.then(() => benchmark(' Hermes Class', HermesSet))
.then(() => benchmark(' Literal Object', Literal))
.then(() => benchmark(' Fake Class', FakeClass))
.then(() => benchmark(' Hermes Class + super', HermesSetSuper))
.then(() => benchmark(' Hermes Class', HermesSet))
;

0 comments on commit fa1ce95

Please sign in to comment.