From fe30cae35ed9fab542c05be41145d4a111193e7d Mon Sep 17 00:00:00 2001 From: Ivan Huz Date: Mon, 10 Feb 2025 17:09:06 +0200 Subject: [PATCH 1/3] Improve final log Comma only appeared in cases where there were a few optimisations in a single `opt' call: `closureInstance....... 330061782 no preopt, interp interp opt, turbofan` An arrow has been added to distinct optimization steps in the final log: `closureInstance....... 213392979 no preopt -> interp -> interp -> opt, turbofan` --- JavaScript/2-benchmark.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/JavaScript/2-benchmark.js b/JavaScript/2-benchmark.js index 9b765e4..22ffd14 100644 --- a/JavaScript/2-benchmark.js +++ b/JavaScript/2-benchmark.js @@ -35,7 +35,7 @@ const opt = fn => { if (n === 0) return; if (Math.pow(2, n) & optStatus) results.push(name); }); - return results.length ? results.join(', ') : 'no preopt,'; + return results.length ? results.join(', ') : 'no preopt'; } const optimize = fn => %OptimizeFunctionOnNextCall(fn); @@ -64,9 +64,8 @@ benchmark.do = (count, tests) => { const diff = end - begin; const name = rpad(fn.name, '.', 22); const iterations = result.length - PRE_COUNT; - const log = [ - name, diff, optBefore, optAfter, optAfterHeat, optAfterLoop - ]; + const opts = [optBefore, optAfter, optAfterHeat, optAfterLoop]; + const log = [name, diff, opts.join(' -> ')]; console.log(log.join(' ')); return { name, time: diff }; }); From 7f3526e68c22d4e1e6a6006871f15cd9e9a1f3a2 Mon Sep 17 00:00:00 2001 From: Ivan Huz Date: Mon, 10 Feb 2025 17:11:47 +0200 Subject: [PATCH 2/3] Fix `closureInstance` `closureInstance` used to return a function instead of an object instance --- JavaScript/3-instantiation.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/JavaScript/3-instantiation.js b/JavaScript/3-instantiation.js index e266438..cbd51dd 100644 --- a/JavaScript/3-instantiation.js +++ b/JavaScript/3-instantiation.js @@ -6,7 +6,8 @@ const makeClosure = (hello, size, flag) => () => ( { hello, size, flag } ); -const closureInstance = () => makeClosure('world', 100500, true); +const closureInstance = makeClosure('world', 100500, true); +const invokeClosure = () => closureInstance(); const defineArray = () => ['world', 100500, true]; @@ -68,7 +69,7 @@ const callFactory = () => itemFactory('world', 100500, true); benchmark.do(1000000, [ callFactory, - closureInstance, + invokeClosure, defineObject, defineArray, defineArrayOfString, From c1281940bd5b3fe6e0fabcbb4731852d041ef638 Mon Sep 17 00:00:00 2001 From: Ivan Huz Date: Mon, 10 Feb 2025 17:17:31 +0200 Subject: [PATCH 3/3] Fix `data1` query Assigned the prototype with `age` property for `data1` elements --- JavaScript/4-array.js | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/JavaScript/4-array.js b/JavaScript/4-array.js index bd498e0..e14f650 100644 --- a/JavaScript/4-array.js +++ b/JavaScript/4-array.js @@ -4,6 +4,15 @@ const benchmark = require('./2-benchmark.js'); // Define Data Source +function AgeComputable() {} +Object.defineProperty(AgeComputable.prototype, 'age', { + get() { + const difference = new Date() - this.birth; + return Math.floor(difference / 31536000000); + }, + enumerable: true, +}); + const data1 = [ { name: 'Marcus Aurelius', birth: new Date('212-04-26'), @@ -20,7 +29,7 @@ const data1 = [ { name: 'Rene Descartes', birth: new Date('1596-03-31'), city: 'La Haye en Touraine' }, -]; +].map((person) => Object.setPrototypeOf(person, AgeComputable.prototype)); const data2 = [ ['Marcus Aurelius', '212-04-26', 'Rome'], @@ -80,11 +89,11 @@ const query = (person) => ( // Execute tests +const filterObjects = () => data1.filter(query); + +const filterArrays = () => data2.filter(query); + benchmark.do(1000000, [ - function filterObjects() { - data1.filter(query); - }, - function filterArrays() { - data2.filter(query); - } + filterObjects, + filterArrays ]); pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy