Skip to content

Instantly share code, notes, and snippets.

View bmeurer's full-sized avatar

Benedikt Meurer bmeurer

View GitHub Profile
@bmeurer
bmeurer / bench-event-emitter.js
Last active October 8, 2017 09:30
Isolated test case for the discussion around rest parameters for Node's EventEmitter (https://github.com/nodejs/node/pull/13155#issuecomment-334706721)
// Isolated test case for the discussion around rest parameters for Node's EventEmitter
// https://github.com/nodejs/node/pull/13155#issuecomment-334706721
if (typeof console === 'undefined') console = {log:print};
const N = 2e7;
const TESTS = [];
(function() {
function emitNone(handler, isFn, self) {
if (isFn)
@bmeurer
bmeurer / mathias.js
Created September 20, 2017 20:55
Following up on discussion at @munichjs how to create packed arrays pre-initialized in V8
"use strict";
// These are examples how to created PACKED_*_ELEMENTS arrays preinitialized
// in V8, following up on offline discussion at the last MunichJS meetup.
function createPackedViaArrayFrom(length, value) {
return Array.from.call(null, Array.prototype.map.call({length}, _ => value));
}
function createPackedViaGenerator(length, value) {
// Micro-benchmark to answer the question in https://twitter.com/thejameskyle/status/905403367949647874
if (typeof console === 'undefined') console = {log:print};
var closuresOriginal = (function() {
const outer = a => {
const inner = b => a + b;
return inner(2);
};
let a = Object.assign({}, {x:1, y:2, z:3});
let b = Object.assign({}, a);
console.log("a is", a);
console.log("b is", b);
console.log("a and b have same map:", %HaveSameMap(a, b));
let a = {x:1, y:2, z:3};
let b = Object.assign({}, a);
console.log("a is", a);
console.log("b is", b);
console.log("a and b have same map:", %HaveSameMap(a, b));
let a = {x:1, y:2, z:3};
let b = {};
b.x = 1;
b.y = 2;
b.z = 3;
console.log("a is", a);
console.log("b is", b);
console.log("a and b have same map:", %HaveSameMap(a, b));
const s1 = todo({}, {
type: 'ADD_TODO',
id: 1,
text: "Finish blog post"
});
const s2 = todo(s1, {
type: 'TOGGLE_TODO',
id: 1
});
const todo = (state = {}, action) => {
switch (action.type) {
case 'ADD_TODO':
return {
id: action.id,
text: action.text,
completed: false
}
case 'TOGGLE_TODO':
if (state.id !== action.id) {
function fibonacci(num){
var a = 1, b = 0, temp;
while (num >= 0){
temp = a;
a = a + b;
b = temp;
--num;
}
@bmeurer
bmeurer / destructuring-performance-test.js
Last active November 17, 2016 06:09
Destructuring performace (V8 ToT 2016/11/16)
/////////////////////////////////////////////////////////////////////////////
// Test framework:
// Warmup
for (var i = 0; i < 1000; ++i) test(data);
function time(test, a) {
let startTime = Date.now();
// Using F.p.apply here to prevent inlining, so we can really
// just measure the performance of test stand-alone.