Skip to content

Instantly share code, notes, and snippets.

@b3nab
Created May 24, 2022 08:50
Show Gist options
  • Save b3nab/abf0e2a5a58f3c1c3f29e8417ca6e41b to your computer and use it in GitHub Desktop.
Save b3nab/abf0e2a5a58f3c1c3f29e8417ca6e41b to your computer and use it in GitHub Desktop.
Untitled benchmark (https://jsbench.github.io/#abf0e2a5a58f3c1c3f29e8417ca6e41b) #jsbench #jsperf
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>Untitled benchmark</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/1.0.0/benchmark.min.js"></script>
<script src="./suite.js"></script>
</head>
<body>
<h1>Open the console to view the results</h1>
<h2><code>cmd + alt + j</code> or <code>ctrl + alt + j</code></h2>
</body>
</html>
"use strict";
(function (factory) {
if (typeof Benchmark !== "undefined") {
factory(Benchmark);
} else {
factory(require("benchmark"));
}
})(function (Benchmark) {
var suite = new Benchmark.Suite;
suite.add("using JSON.stringify(car) === JSON.stringify(currentCar)", function () {
// using JSON.stringify(car) === JSON.stringify(currentCar)
const car = {
vin: 'XXX123XXX',
brand: 'BRAND',
model: 'bla'
}
const cars = [
{
vin: 'XXX123XXX',
brand: 'BRAND',
model: 'bla'
},{
vin: 'YYY000YYY',
brand: 'BRAND',
model: 'bla'
},{
vin: 'ASDASDASD',
brand: 'BRAND',
model: 'bla'
},{
vin: 'VINVINVIN',
brand: 'BRAND',
model: 'bla'
},{
vin: 'TESTVIN12',
brand: 'BRAND',
model: 'bla'
},
]
cars.map(c => {
const bool0 = JSON.stringify(c) === JSON.stringify(car);
const bool1 = JSON.stringify(c) === JSON.stringify(car);
const bool2 = JSON.stringify(c) === JSON.stringify(car);
const bool3 = JSON.stringify(c) === JSON.stringify(car);
const bool4 = JSON.stringify(c) === JSON.stringify(car);
const bool5 = JSON.stringify(c) === JSON.stringify(car);
const bool6 = JSON.stringify(c) === JSON.stringify(car);
const bool7 = JSON.stringify(c) === JSON.stringify(car);
const bool8 = JSON.stringify(c) === JSON.stringify(car);
const bool9 = JSON.stringify(c) === JSON.stringify(car);
return bool0 && bool1 && bool2 && bool3 && bool4 && bool5 && bool6 && bool7 && bool8 && bool9;
});
});
suite.add("using car.vin === currentCar.vin", function () {
// using car.vin === currentCar.vin
const car = {
vin: 'XXX123XXX',
brand: 'BRAND',
model: 'bla'
}
const cars = [
{
vin: 'XXX123XXX',
brand: 'BRAND',
model: 'bla'
},{
vin: 'YYY000YYY',
brand: 'BRAND',
model: 'bla'
},{
vin: 'ASDASDASD',
brand: 'BRAND',
model: 'bla'
},{
vin: 'VINVINVIN',
brand: 'BRAND',
model: 'bla'
},{
vin: 'TESTVIN12',
brand: 'BRAND',
model: 'bla'
},
]
cars.map(c => {
const bool0 = c.vin === car.vin;
const bool1 = c.vin === car.vin;
const bool2 = c.vin === car.vin;
const bool3 = c.vin === car.vin;
const bool4 = c.vin === car.vin;
const bool5 = c.vin === car.vin;
const bool6 = c.vin === car.vin;
const bool7 = c.vin === car.vin;
const bool8 = c.vin === car.vin;
const bool9 = c.vin === car.vin;
return bool0 && bool1 && bool2 && bool3 && bool4 && bool5 && bool6 && bool7 && bool8 && bool9;
});
});
suite.on("cycle", function (evt) {
console.log(" - " + evt.target);
});
suite.on("complete", function (evt) {
console.log(new Array(30).join("-"));
var results = evt.currentTarget.sort(function (a, b) {
return b.hz - a.hz;
});
results.forEach(function (item) {
console.log((idx + 1) + ". " + item);
});
});
console.log("Untitled benchmark");
console.log(new Array(30).join("-"));
suite.run();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment