Skip to content

Instantly share code, notes, and snippets.

View kelgendy1204's full-sized avatar

Khaled Saad kelgendy1204

  • Gemany
View GitHub Profile
@kelgendy1204
kelgendy1204 / blocking-task.js
Created June 24, 2024 10:31
Blocking event loop in nodejs for different threads
const { parentPort } = require('worker_threads');
function blockForSeconds(seconds) {
const startTime = Date.now();
let endTime = startTime;
while (endTime - startTime < seconds * 1000) {
endTime = Date.now();
}
}
@kelgendy1204
kelgendy1204 / main.js
Created June 24, 2024 10:27
Blocking event loop in nodejs
function blockForSeconds(seconds) {
const startTime = Date.now();
let endTime = startTime;
while (endTime - startTime < seconds * 1000) {
endTime = Date.now();
}
}
function run() {
const startTime = performance.now();
@kelgendy1204
kelgendy1204 / ab-testing.js
Last active June 2, 2021 15:08
A/B testing 2 different approaches
function createSamples(name, createVariation) {
const sampleCount = 10000;
const variations = [];
for (let i = 0; i < sampleCount; i++) {
variations.push(createVariation());
}
const countData = variations.reduce((accum, curr) => {
if (accum[curr]) {