Skip to content

Instantly share code, notes, and snippets.

@F1LT3R
Last active August 11, 2020 13:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save F1LT3R/80763bde9b42bcca3275f76c241fc665 to your computer and use it in GitHub Desktop.
Save F1LT3R/80763bde9b42bcca3275f76c241fc665 to your computer and use it in GitHub Desktop.
Hash Map Perf.
const hash = {
a: 1,
b: 1,
c: 1,
d: 1,
e: 1,
g: 1,
h: 1,
j: 1,
k: 1,
l: 1,
m: 1,
n: 1,
o: 1,
p: 1,
q: 1,
r: 1,
s: 1,
t: 1,
u: 1,
v: 1,
w: 1,
x: 1,
y: 1,
z: 1,
a1: 1,
b1: 1,
c1: 1,
d1: 1,
e1: 1,
g1: 1,
h1: 1,
j1: 1,
k1: 1,
l1: 1,
m1: 1,
n1: 1,
o1: 1,
p1: 1,
q1: 1,
r1: 1,
s1: 1,
t1: 1,
u1: 1,
v1: 1,
w1: 1,
x1: 1,
y1: 1,
z1: 1,
};
const time = () => Number(new Date());
// Four Hundred Billion Iterations
const iterations = 400000000000;
const start2 = time();
let count2 = 0;
for (let i = 0; i < iterations; i += 1) {
count2 += hash.z1;
}
console.log("z1", count2 === iterations);
const elapsed2 = time() - start2;
console.log("z1", elapsed2);
const start = time();
let count = 0;
for (let i = 0; i < iterations; i += 1) {
count += hash.a;
}
console.log("a", count === iterations);
const elapsed = time() - start;
console.log("a", elapsed);
// "A" always wins... just.
// ❯ node hashspeed.js
// z1 true
// z1 356436
// a true
// a 355654
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment