Skip to content

Instantly share code, notes, and snippets.

View bench-dom-serialize-flatten.js
// Copyright 2013-2019 Benedikt Meurer
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// <https://www.apache.org/licenses/LICENSE-2.0>
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
@bmeurer
bmeurer / bench-instanceof-versus-typeof-megamorphic.js
Created Jan 28, 2019
Demonstrate the performance impact of using `instanceof` vs. checking for some existing property (in the megamorphic case)
View bench-instanceof-versus-typeof-megamorphic.js
// Copyright 2013-2019 Benedikt Meurer
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// <https://www.apache.org/licenses/LICENSE-2.0>
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
@bmeurer
bmeurer / prerender-global-_serializeOne.diff
Last active Jan 28, 2019
Angular Universal Prerendering test case
View prerender-global-_serializeOne.diff
--- dist/prerender_ORIG.js 2019-01-28 11:32:34.000000000 +0100
+++ dist/prerender.js 2019-01-28 11:33:58.000000000 +0100
@@ -88604,66 +88604,7 @@
serialize: { value: function() {
var s = '';
for (var kid = this.firstChild; kid !== null; kid = kid.nextSibling) {
- s += kid._serializeOne(this);
- }
- return s;
- }},
View surma.js
// Microbenchmark to investigate https://twitter.com/DasSurma/status/927324384238473222
var isEvenNum = (num = 1) => num !== 0 && num % 2 === 0;
var sqrNum = num => num * num;
var N = 1000;
var arr = [];
for (n = 1; n <= 10000; ++n) arr.push(n);
function multiloops() {
View bench-babylon-forin.js
// Benchmark for the PR https://github.com/babel/babel/pull/6748
"use strict";
// Object with no enumerable properties in the prototype chain.
const a = {x:1, y:2, z:3};
// Object with enumerable properties in the prototype chain.
function B() { this.x = 1; this.y = 2; this.z = 3; }
B.prototype.foo = 4;
View bench-beyond-length.js
// Benchmark to measure loops running until OOB vs. loops that run
// to length. See
//
// https://v8project.blogspot.de/2017/09/elements-kinds-in-v8.html#avoid-reading-beyond-length
//
// for background. While OOB access is now no longer almost 10x
// slower in V8, it's still an anti-pattern that should be avoided.
"use strict";
@bmeurer
bmeurer / bench-event-emitter.js
Last active Oct 8, 2017
Isolated test case for the discussion around rest parameters for Node's EventEmitter (https://github.com/nodejs/node/pull/13155#issuecomment-334706721)
View bench-event-emitter.js
// 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 Sep 20, 2017
Following up on discussion at @munichjs how to create packed arrays pre-initialized in V8
View mathias.js
"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) {
View bench-james.js
// 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);
};
View object-assign-everywhere.js
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));