-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
2. Add distinct benchmark 3. Remove asserts from benchmarks. 4. Add binary search and insert in ordered place utils methods.
- Loading branch information
1 parent
c8643f7
commit 21f414a
Showing
16 changed files
with
283 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export { fromIterable, fromObject, fromArrayLike, range, from } from './src/index'; | ||
export { fromIterable, fromObject, fromArrayLike, range, from, repeat } from './src/index'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { BaseLinqIterable } from "../base-linq-iterable"; | ||
export class RepeatIterable extends BaseLinqIterable { | ||
constructor(value, times) { | ||
super([]); | ||
this.value = value; | ||
this.times = times; | ||
} | ||
|
||
get() { | ||
return this; | ||
} | ||
|
||
[Symbol.iterator]() { | ||
let indx = 0; | ||
const max = this.times; | ||
const item = this.value; | ||
return { | ||
next() { | ||
if (indx < max) { | ||
indx++; | ||
return { done: false, value: item }; | ||
} else { | ||
return { done: true } | ||
} | ||
} | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import Benchmark from "benchmark"; | ||
import { Person } from "../unit/models"; | ||
import { from, range, repeat } from "../../index.esm"; | ||
|
||
const iterable = new Set(repeat(0, 10000).concat(repeat(1, 100000))); | ||
const array = Array.from(iterable); | ||
|
||
export const distinctCompareIterableBenchmark = new Benchmark('[distinct] Distinct iterable with compare', () => { | ||
from(iterable).distinct((a, b) => a === b).toArray(); | ||
}); | ||
|
||
export const distinctIterableBenchmark = new Benchmark('[distinct] Distinct iterable', () => { | ||
from(iterable).distinct().toArray(); | ||
}); | ||
|
||
export const distinctCompareArrayBenchmark = new Benchmark('[distinct] Distinct array with compare', () => { | ||
from(array).distinct((a, b) => a === b).toArray(); | ||
}); | ||
|
||
export const distinctArrayBenchmark = new Benchmark('[distinct] Distinct array', () => { | ||
from(array).distinct().toArray(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,18 @@ | ||
import { range, from } from '../../index.esm.js'; | ||
import chai from 'chai'; | ||
import Benchmark from 'benchmark'; | ||
|
||
const assert = chai.assert; | ||
|
||
const arrayLength = 100000; | ||
const iterable = new Set(range(0, arrayLength)); | ||
const array = Array.from(iterable); | ||
|
||
export const arrayMapBenchmark = new Benchmark('[select] Array map', () => { | ||
const res = array.map(_ => _ * 3); | ||
assert.equal(res.length, arrayLength); | ||
array.map(_ => _ * 3); | ||
}); | ||
|
||
export const selectArrayInput = new Benchmark('[select] array input', () => { | ||
const res = from(array).select(_ => _ * 3).toArray(); | ||
assert.equal(res.length, arrayLength); | ||
from(array).select(_ => _ * 3).toArray(); | ||
}); | ||
|
||
export const selectIterableInput = new Benchmark('[select] iterable input', () => { | ||
const res = from(iterable).select(_ => _ * 3).toArray(); | ||
assert.equal(res.length, arrayLength); | ||
from(iterable).select(_ => _ * 3).toArray(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,21 @@ | ||
import { range, from } from '../../index.esm.js'; | ||
import chai from 'chai'; | ||
import Benchmark from 'benchmark'; | ||
|
||
const assert = chai.assert; | ||
const arrayLength = 100000; | ||
const lengthToSkip = 1000; | ||
const expected = arrayLength - lengthToSkip; | ||
|
||
const iterable = new Set(range(0, arrayLength)); | ||
const array = Array.from(iterable); | ||
|
||
export const arraySliceBenchmark = new Benchmark('[skip] Array slice', () => { | ||
const res = array.slice(lengthToSkip, arrayLength); | ||
assert.equal(res.length, expected); | ||
array.slice(lengthToSkip, arrayLength); | ||
}); | ||
|
||
export const skipArrayInput = new Benchmark('[skip] array input', () => { | ||
const res = from(array).skip(lengthToSkip).toArray(); | ||
assert.equal(res.length, expected); | ||
from(array).skip(lengthToSkip).toArray(); | ||
}); | ||
|
||
export const skipIterableInput = new Benchmark('[skip] iterable input', () => { | ||
const res = from(iterable).skip(lengthToSkip).toArray(); | ||
assert.equal(res.length, expected); | ||
from(iterable).skip(lengthToSkip).toArray(); | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,21 @@ | ||
import { range, from } from '../../index.esm.js'; | ||
import chai from 'chai'; | ||
import Benchmark from 'benchmark'; | ||
|
||
const assert = chai.assert; | ||
|
||
const arrayLength = 100000; | ||
const iterable = new Set(range(0, arrayLength)); | ||
const array = Array.from(iterable); | ||
const lengthToTake = 1000; | ||
|
||
export const arraySliceBenchmark = new Benchmark('[take] Array slice', () => { | ||
const res = array.slice(0, lengthToTake); | ||
assert.equal(res.length, lengthToTake); | ||
array.slice(0, lengthToTake); | ||
}); | ||
|
||
export const takeArrayInput = new Benchmark('[take] array input', () => { | ||
const res = from(array).take(lengthToTake).toArray(); | ||
assert.equal(res.length, lengthToTake); | ||
from(array).take(lengthToTake).toArray(); | ||
}); | ||
|
||
export const takeIterableInput = new Benchmark('[take] iterable input', () => { | ||
const res = from(iterable).take(lengthToTake).toArray(); | ||
assert.equal(res.length, lengthToTake); | ||
from(iterable).take(lengthToTake).toArray(); | ||
}); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,18 @@ | ||
import { range, from } from '../../index.esm.js'; | ||
import chai from 'chai'; | ||
import Benchmark from 'benchmark'; | ||
|
||
const assert = chai.assert; | ||
|
||
const arrayLength = 100000; | ||
const iterable = new Set(range(0, arrayLength)); | ||
const array = Array.from(iterable); | ||
|
||
export const arrayFilterBenchmark = new Benchmark('[where] Array filter', () => { | ||
const res = array.filter(_ => _ % 2 === 1); | ||
assert.equal(res.length, arrayLength / 2); | ||
array.filter(_ => _ % 2 === 1); | ||
}); | ||
|
||
export const whereArrayInput = new Benchmark('[where] array input', () => { | ||
const res = from(array).where(_ => _ % 2 === 1).toArray(); | ||
assert.equal(res.length, arrayLength / 2); | ||
from(array).where(_ => _ % 2 === 1).toArray(); | ||
}); | ||
|
||
export const whereIterableInput = new Benchmark('[where] iterable input', () => { | ||
const res = from(iterable).where(_ => _ % 2 === 1).toArray(); | ||
assert.equal(res.length, arrayLength / 2); | ||
from(iterable).where(_ => _ % 2 === 1).toArray(); | ||
}); |
Oops, something went wrong.