PS object.values vs for-in

Benchmark created by scheibo on


Setup

const stats = {hp: 101, atk: 99, def: 102, spa: 98, spd: 103, spe: 97};
  let bst = 0;

Test runner

Ready to run.

Testing in
TestOps/sec
for..in
let statName;
for (statName in stats) {
  bst += stats[statName] * Math.random();
}
ready
Object.values
for (const stat of Object.values(stats)) {
  bst += stat * Math.random();
}
ready
Object.values cached
let values = Object.values(stats);
for (const stat of values) {
  bst += stat * Math.random();
}
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.