Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
class A {
get [Symbol.toStringTag]() { return "A"; }
}
const numbers = [0, 0.5, 1, Math.pow(2,32)-1, Infinity];
const strings = ["", '0', 'abcde', "Hello World", '6'.repeat(100)];
const objects = [{}, [], new A, Object.prototype, x => x];
const values = [{}, 0, '', x => x, []];
const n = 1e6;
function Numbers() {
let result = "";
for (const number of numbers) {
for (let i = 0; i < n; ++i) {
result = Object.prototype.toString.call(number);
}
}
return result;
}
function Strings() {
let result = "";
for (const string of strings) {
for (let i = 0; i < n; ++i) {
result = Object.prototype.toString.call(string);
}
}
return result;
}
function Objects() {
let result = "";
for (const object of objects) {
for (let i = 0; i < n; ++i) {
result = Object.prototype.toString.call(object);
}
}
return result;
}
function Values() {
let result = "";
for (const value of values) {
for (let i = 0; i < n; ++i) {
result = Object.prototype.toString.call(value);
}
}
return result;
}
var TESTS = [
Numbers,
Strings,
Objects,
Values
];
// Warmup.
for (let i = 0; i < 10; ++i) {
for (const test of TESTS) test();
}
// Actual tests.
for (const test of TESTS) {
console.time(test.name);
test();
console.timeEnd(test.name);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment