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:...
// 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,
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
//
// 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;
@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;
- }},
@bmeurer
bmeurer / gist:1026439
Created June 15, 2011 03:51
Nice transition from splash screen to main application screen using fade out and zoom in animation. Change the -application:didFinishLaunchingWithOptions: method of your application delegate class like this (assuming your splash image is named Default.png
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Put necessary initialization steps here...
// Add imageView overlay with fade out and zoom in animation
UIImageView *imageView = [[UIImageView alloc] initWithFrame:self.window.frame];
imageView.image = [UIImage imageNamed:@"Default"]; // assuming your splash image is "Default.png" or "Default@2x.png"
[self.window addSubview:imageView];
[self.window bringSubviewToFront:imageView];
[UIView transitionWithView:self.window
// 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 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";