Skip to content

Instantly share code, notes, and snippets.

@caderek
caderek / remove-spaces.perf.js
Created January 11, 2023 23:00
Remove spaces benchmark
import b from "benny";
import {
removeSpaces,
removeSpaces2,
removeSpaces3,
removeSpaces4,
} from "./code.js";
{
const NUMBER_OF_FORMULAS = 1000;
const generateName = (num) => {
const charCode = (num % (122 - 96)) + 97;
const count = Math.floor(num / 26);
return String.fromCharCode(charCode).repeat(count + 1);
};
const formulas = new Map(
import b from "benny";
import calculateWithObject from "./calculate-with-object.js";
import calculateWithMap from "./calculate-with-map.js";
b.suite(
"calculate",
b.add("calculate with object", () => {
calculateWithObject("average", 1, 1);
}),
const NUMBER_OF_FORMULAS = 1000;
const generateName = (num) => {
const charCode = (num % (122 - 96)) + 97;
const count = Math.floor(num / 26);
return String.fromCharCode(charCode).repeat(count + 1);
};
const formulas = new Map(
const NUMBER_OF_FORMULAS = 1000;
const generateName = (num) => {
const charCode = (num % (122 - 96)) + 97;
const count = Math.floor(num / 26);
return String.fromCharCode(charCode).repeat(count + 1);
};
const formulas = Object.fromEntries(
@caderek
caderek / btc_consumption.js
Last active June 28, 2022 14:09
Bitcoin energy consumption calculator
const US_CONSUMPTION = 3930;
const halvings = [
new Date("2012.11.28").getTime(),
new Date("2016.07.09").getTime(),
new Date("2020.05.11").getTime(),
...new Array(30) // 30 more cycles until year 2140
.fill(0)
.map(
(_, i) =>
@caderek
caderek / run.js
Created December 4, 2021 17:43
Aocrunner test input formatting
run({
part1: {
tests: [
{
input: `forward 5
down 5
forward 8
up 3
down 8
forward 2`,
@caderek
caderek / Duck_factory2.js
Last active November 23, 2021 01:34
Object composition - factory part 2
const Swimmable = () => ({
speed: 1,
swim() {
console.log(`Swam ${this.speed} meter(s)`)
},
})
const Quackable = () => ({
speed: 1,
quack() {
@caderek
caderek / Duck_factory1.js
Last active November 23, 2021 01:35
Object composition - factory part 1
const Swimmable = () => ({
swim() {
console.log("Swam 1 meter")
},
})
const Quackable = () => ({
quack() {
console.log("Quack!")
},
@caderek
caderek / Duck_class2.js
Last active November 23, 2021 01:35
Object composition - class part 2
class Swimmable {
constructor() {
this.speed = 1
}
swim() {
console.log(`Swam ${this.speed} meter(s)`)
}
}