Skip to content

Instantly share code, notes, and snippets.

View bmeurer's full-sized avatar

Benedikt Meurer bmeurer

View GitHub Profile
const originalError = console.error;
console.error = function(...args) {
originalError(...args, "foo");
}
//# sourceMappingURL=data:...
import MagicString from 'magic-string';
import open from 'open';
function magic_string_replace_all(src, search, replace) {
let idx = src.original.indexOf(search);
if (idx == -1) throw new Error('search not found in src');
do {
src.update(idx, idx + search.length, replace, {storeName: true});
} while ((idx = src.original.indexOf(search, idx + 1)) != -1);
}
@bmeurer
bmeurer / standalone.js
Created January 2, 2022 13:19
Standalone d8 performance test for Runtime.setMaxCallStackSizeToCapture
// Copyright (c) 2022 Benedikt Meurer. All rights reserved.
//
// Run this test with
//
// d8 --enable-inspector standalone.js -- -1
//
// to measure with the inspector disabled, or with
//
// d8 --enable-inspector standalone.js -- 0
//
// 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 January 28, 2019 15:10
Demonstrate the performance impact of using `instanceof` vs. checking for some existing property (in the megamorphic case)
// 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 January 28, 2019 10:55
Angular Universal Prerendering test case
--- 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;
- }},
// 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() {
// 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;
// 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 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)