Skip to content

Instantly share code, notes, and snippets.

View robpalme's full-sized avatar

Rob Palmer robpalme

  • Bloomberg L.P.
  • London
View GitHub Profile
@robpalme
robpalme / bench-sam.js
Last active August 13, 2017 16:08 — forked from bmeurer/bench-sam.js
Add aafeApplyFunctionsRest
function applyFunctionsRest(functions, ...args) {
for (var i = 0, l = functions.length; i < l; ++i) {
functions[i].apply(this, args);
}
}
var safeApply = Function.prototype.call.bind(Function.prototype.apply);
function safeApplyFunctionsRest(functions, ...args) {
for (var i = 0, l = functions.length; i < l; ++i) {
@robpalme
robpalme / defineProperty.js
Created August 15, 2017 09:21
defineProperty vs standard property assignment
const TEST_LOOP_COUNT = 1e5;
const VAL = "woo";
const DESC = { value: VAL, configurable: true, enumerable: true, writable: true };
const propNames = [ "i0", "i1", "i2", "i3", "i4", "i5", "i6", "i7", "i8", "i9" ];
const PROP_COUNT = propNames.length;
function literal () {
return {
[propNames[0]]: VAL,
@robpalme
robpalme / linear-search.js
Last active August 22, 2017 07:59
Linear string search perf
(function() {
const Y_IX = 1e6;
const str = "x".repeat(Y_IX) + "y";
function regexp (str) {
return /y/.exec(str).index;
}
// 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);
};
@robpalme
robpalme / bench-james-both.js
Created September 7, 2017 07:58
Creation & call times for different binding techniques
// 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);
};
@robpalme
robpalme / function-constructor-base-cost.js
Created October 17, 2018 07:58
Compare calling Function() once-per-function vs first concatenating source text into an array of functions
{
function empty () {}
const fnsLength = 10;
const fns = new Array(fnsLength).fill(empty);
const fnStrings = fns.map(x => x.toString());
var ix = 0;
@robpalme
robpalme / tsc-optimized.js
Last active July 2, 2020 08:20
Property-to-Var optimisation on TypeScript Compiler
var ts_versionMajorMinor,
ts_version,
ts_tryGetNativeMap,
ts_Map,
ts_createMapShim,
ts_emptyArray,
ts_createMap,
ts_createMapFromEntries,
ts_createMapFromTemplate,
ts_length,