Skip to content

Instantly share code, notes, and snippets.

View Aschen's full-sized avatar
💭
:trollface:

Adrien Maret Aschen

💭
:trollface:
View GitHub Profile
@Aschen
Aschen / benchmark.js
Created January 14, 2020 07:08
Closur optim
const
PipeRunner = require('./pipeRunner');
const now = (unit) => {
const hrTime = process.hrtime();
switch (unit) {
case 'milli':
@Aschen
Aschen / benchmark.js
Created January 14, 2020 09:23
Closur optim
const
PipeRunner = require('./pipeRunner');
const now = (unit) => {
const hrTime = process.hrtime();
switch (unit) {
case 'milli':
@Aschen
Aschen / README.md
Last active February 10, 2020 03:01
Benchmarking Kuzzle Realtime Engine latency

Benchmarking Kuzzle Realtime Engine latency

Run the subscriber script:

node realtime-latency-benchmark.js sub

Then you can run publisher scripts:

node realtime-latency-benchmark.js pub
@Aschen
Aschen / results.txt
Last active February 12, 2020 02:40
Benchmark returning promises
node bench/returning-promises.js
standard x 3,096,388 ops/sec ±0.77% (91 runs sampled)
async wrapped x 1,853,672 ops/sec ±1.12% (81 runs sampled)
await then return x 1,074,238 ops/sec ±1.96% (53 runs sampled)
Fastest is standard
@Aschen
Aschen / int32_vs_float64.cr
Created March 29, 2020 04:45
Int32 vs Float64 performances in Crystal
# https://stackoverflow.com/questions/60910274/int32-vs-float64-performances-in-crystal
require "benchmark"
def percentage_diff(number_a, number_b)
small_number = (number_a > number_b) ? number_b : number_a
big_number = (number_a < number_b) ? number_b : number_a
(big_number - small_number) / small_number
end
@Aschen
Aschen / README.md
Last active January 17, 2025 05:31
Benchmarking AsyncLocalStorage

What is the overhead of AsyncLocalStorage?

Run the benchmark:

$ npm i benchmark

# Run the AsyncLocalStorage benchmark
$ node async-local-storage.js ASL
ASL x 15,551 ops/sec ±3.30% (79 runs sampled)
const app = express();
const log = message => console.log(message);
const emailService = new EmailService(logger);
app.get('/', (request, response) => {
const requestId = uuid();
log(`[${requestId}] Start processing`);
await emailService.notify(request.body.emails, requestId);
class EmailService {
constructor (log) {
this.log = log;
}
async notify (emails, requestId) {
for (const email of emails) {
this.log(`[${requestId}] Send email: ${email}`);
sendGrid.send(email);
}
const { AsyncLocalStorage } = require('async_hooks');
const asyncLocalStorage = new AsyncLocalStorage();
app.get('/', (request, response) => {
const requestId = uuid();
asyncLocalStorage.run(requestId, async () => {
// entering asynchronous context
log('Start processing');
await emailService.notify(request.body.emails);
const log = message => {
const requestId = asyncLocalStorage.getStore();
if (requestId) {
console.log(`[${requestId}] ${message}`);
}
else {
console.log(message);
}
};