-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(benchmarks): move benchmarks to individual files
- Loading branch information
1 parent
0d43dd3
commit 85561bc
Showing
6 changed files
with
113 additions
and
51 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/** | ||
* Created by tushar.mathur on 05/11/16. | ||
*/ | ||
|
||
|
||
import {fromArray} from '../src/sources/FromArray' | ||
import {filter} from '../src/operators/Filter' | ||
import {map} from '../src/operators/Map' | ||
import {reduce} from '../src/operators/Reduce' | ||
import {Suite} from 'benchmark' | ||
import {run, sum, add1, even, array, onCycle} from './lib' | ||
|
||
const a = array(1e6) | ||
export function fromArray_map_reduce () { | ||
const suite = new Suite() | ||
suite.add( | ||
'file -> map -> reduce', | ||
(d: any) => run(reduce(sum, 0, map(add1, filter(even, fromArray(a)))), d), | ||
{defer: true} | ||
).on('cycle', onCycle).run() | ||
} |
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,20 @@ | ||
/** | ||
* Created by tushar.mathur on 05/11/16. | ||
*/ | ||
|
||
|
||
import {IDefered, run, passthrough, sum, onCycle, array} from './lib' | ||
import {reduce} from '../src/operators/Reduce' | ||
import {scan} from '../src/operators/Scan' | ||
import {fromArray} from '../src/sources/FromArray' | ||
import {Suite} from 'benchmark' | ||
|
||
const a = array(1e6) | ||
export function fromArray_scan_reduce () { | ||
const suite = new Suite() | ||
suite.add( | ||
'file -> scan -> reduce', | ||
(d: IDefered) => run(reduce(passthrough, 0, scan(sum, 0, fromArray(a))), d), | ||
{defer: true} | ||
).on('cycle', onCycle).run() | ||
} |
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,18 @@ | ||
/** | ||
* Created by tushar.mathur on 05/11/16. | ||
*/ | ||
|
||
import {Suite} from 'benchmark' | ||
import {fromArray} from '../src/sources/FromArray' | ||
import {IDefered, run, array, onCycle} from './lib' | ||
import {slice} from '../src/operators/Slice' | ||
|
||
const a = array(1e6) | ||
export function fromArray_takeN () { | ||
const suite = new Suite() | ||
suite.add('file -> takeN(0, n/10)', | ||
(d: IDefered) => | ||
run(slice(0, 1e6 / 10, fromArray(a)), d), | ||
{defer: true} | ||
).on('cycle', onCycle).run() | ||
} |
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,41 @@ | ||
/** | ||
* Created by tushar.mathur on 05/11/16. | ||
*/ | ||
|
||
|
||
import {IObservable} from '../src/types/core/IObservable' | ||
import {Observer} from '../src/lib/Observer' | ||
import {DefaultScheduler} from '../src/scheduling/DefaultScheduler' | ||
|
||
export interface IDefered { | ||
resolve (): void | ||
} | ||
export function add1 (x: number) { | ||
return x + 1 | ||
} | ||
export function even (e: number) { | ||
return e % 2 === 0 | ||
} | ||
export function sum (a: number, b: number) { | ||
return a + b | ||
} | ||
|
||
export function passthrough (z: any, x: any) { | ||
return x | ||
} | ||
|
||
export const scheduler = new DefaultScheduler() | ||
|
||
export function run (observable: IObservable<any>, d: IDefered) { | ||
observable.subscribe(Observer.of(undefined, undefined, () => d.resolve()), scheduler) | ||
} | ||
|
||
export function array (n: number) { | ||
const a = new Array(n) | ||
for (var i = 0; i < a.length; ++i) { | ||
a[i] = i | ||
} | ||
return a | ||
} | ||
|
||
export const onCycle = (event: any) => console.log(String(event.target)) |
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,5 +1,6 @@ | ||
{ | ||
"globalDependencies": { | ||
"benchmark": "registry:dt/benchmark#1.0.0+20160317120654" | ||
"benchmark": "registry:dt/benchmark#1.0.0+20160317120654", | ||
"node": "registry:dt/node#6.0.0+20161019125345" | ||
} | ||
} |