Skip to content

Improve examples #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions JavaScript/2-benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 };
});
Expand Down
5 changes: 3 additions & 2 deletions JavaScript/3-instantiation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand Down Expand Up @@ -68,7 +69,7 @@ const callFactory = () => itemFactory('world', 100500, true);

benchmark.do(1000000, [
callFactory,
closureInstance,
invokeClosure,
defineObject,
defineArray,
defineArrayOfString,
Expand Down
23 changes: 16 additions & 7 deletions JavaScript/4-array.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand All @@ -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'],
Expand Down Expand Up @@ -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