Skip to content

Commit 196675c

Browse files
🚧 progress(benchmark/fromIterable): Add Array construction.
For comparison.
1 parent a7dad80 commit 196675c

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed

_benchmark/_fixtures.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import fs from 'fs';
2+
import process from 'process';
23

34
export function packageInfo(packageName) {
45
const file = `node_modules/${packageName}/package.json`;
@@ -47,3 +48,14 @@ export const dependency = (name) => ({
4748
};
4849
},
4950
});
51+
52+
export const object = (name, exports) => ({
53+
name,
54+
async load() {
55+
return {
56+
name,
57+
version: process.version,
58+
exports,
59+
};
60+
},
61+
});

_benchmark/fromIterable.js

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import assert from 'assert';
2+
13
import 'regenerator-runtime/runtime.js';
24
import {ArgumentParser} from 'argparse';
35

@@ -10,7 +12,7 @@ import {
1012
iterableToString,
1113
} from '../test/src/_fixtures.js';
1214

13-
import {dist, dependency} from './_fixtures.js';
15+
import {dist, dependency, object} from './_fixtures.js';
1416

1517
const parser = new ArgumentParser();
1618
parser.add_argument('filter');
@@ -21,6 +23,7 @@ const cjs = dist('cjs');
2123
const module = dist('module.js');
2224
const modern = dist('modern.js');
2325
const list = dependency('list');
26+
const array = object('Array', Array);
2427

2528
const suite = new Benchtable('Tree Construction', {isTransposed: false});
2629

@@ -79,6 +82,18 @@ const append = makeFn({
7982
},
8083
});
8184

85+
const push = makeFn({
86+
name: 'push',
87+
build: ({exports}) => {
88+
const {empty} = exports;
89+
return (measure, iterable) => {
90+
let l = empty(measure);
91+
for (const x of iterable) l = l.push(x);
92+
return l;
93+
};
94+
},
95+
});
96+
8297
const prepend = makeFn({
8398
name: 'prepend',
8499
build: ({exports}) => {
@@ -96,7 +111,7 @@ const listFrom = makeFn({
96111
});
97112

98113
const listAppend = makeFn({
99-
name: 'append',
114+
name: 'push',
100115
build: ({exports}) => {
101116
const {empty, append} = exports;
102117
return (_measure, iterable) => {
@@ -107,18 +122,35 @@ const listAppend = makeFn({
107122
},
108123
});
109124

125+
const arrayPush = makeFn({
126+
name: 'push',
127+
build: ({exports}) => {
128+
assert(exports === Array);
129+
return (_measure, iterable) => {
130+
const l = [];
131+
for (const x of iterable) l.push(x);
132+
return l;
133+
};
134+
},
135+
});
136+
110137
await add(cjs, from);
111138
await add(cjs, append);
112139
await add(cjs, prepend);
140+
await add(cjs, push);
113141
await add(module, from);
114142
await add(module, append);
115143
await add(module, prepend);
144+
await add(module, push);
116145
await add(modern, from);
117146
await add(modern, append);
118147
await add(modern, prepend);
148+
await add(modern, push);
119149

120150
await add(list, listFrom);
121151
await add(list, listAppend);
152+
await add(array, listFrom);
153+
await add(array, arrayPush);
122154

123155
const addTitle = (input) => {
124156
const {measure, iterable} = input;

0 commit comments

Comments
 (0)