You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.0 KiB
TypeScript
55 lines
1.0 KiB
TypeScript
const lua: string[] = [
|
|
"zero",
|
|
"one",
|
|
"two",
|
|
"three",
|
|
"four",
|
|
"five",
|
|
"six",
|
|
"seven",
|
|
"eight",
|
|
"nine"
|
|
];
|
|
|
|
Deno.bench("randomgen", () => {
|
|
lua[Math.round(Math.random() * 10)];
|
|
});
|
|
|
|
Deno.bench("switch", () => {
|
|
const input = lua[Math.round(Math.random() * 10)];
|
|
|
|
let a;
|
|
|
|
switch (input) {
|
|
case "zero": a = 0; break;
|
|
case "one": a = 1; break;
|
|
case "two": a = 2; break;
|
|
case "three": a = 3; break;
|
|
case "four": a = 4; break;
|
|
case "five": a = 5; break;
|
|
case "six": a = 6; break;
|
|
case "seven": a = 7; break;
|
|
case "eight": a = 8; break;
|
|
case "nine": a = 9; break;
|
|
}
|
|
});
|
|
|
|
Deno.bench("lookup table", () => {
|
|
const input = lua[Math.round(Math.random() * 10)];
|
|
|
|
const lut: Record<string, number> = {
|
|
zero: 0,
|
|
one: 1,
|
|
two: 2,
|
|
three: 3,
|
|
four: 4,
|
|
five: 5,
|
|
six: 6,
|
|
seven: 7,
|
|
eight: 8,
|
|
nine: 9
|
|
};
|
|
|
|
const a = lut[input];
|
|
});
|