Skip to content

Commit

Permalink
more benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
martinsik authored and davidwdan committed Apr 5, 2017
1 parent cea5ee5 commit 02f79e4
Show file tree
Hide file tree
Showing 43 changed files with 539 additions and 22 deletions.
12 changes: 12 additions & 0 deletions benchmark/catch/catch.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

use Rx\Observable;

$source = Observable::error(new \Exception('error'))
->catchError(function() {
return Observable::just(25);
});

return function() use ($source) {
return $source;
};
12 changes: 12 additions & 0 deletions benchmark/combineLatest/combineLatest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

use Rx\Observable;

$source = Observable::range(0, 25)
->combineLatest([Observable::range(0, 25)], function($a, $b) {
return $a + $b;
});

return function() use ($source) {
return $source;
};
19 changes: 19 additions & 0 deletions benchmark/combineLatest/combineLatest_eventloop.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

use Rx\Observable;
use Rx\Scheduler\EventLoopScheduler;
use React\EventLoop\StreamSelectLoop;

$loop = new StreamSelectLoop();
$scheduler = new EventLoopScheduler($loop);

$source = Observable::range(0, 25, $scheduler)
->combineLatest([Observable::range(0, 25, $scheduler)], function($a, $b) {
return $a + $b;
});

$factory = function() use ($source) {
return $source;
};

return [$factory, $loop];
4 changes: 2 additions & 2 deletions benchmark/concat/concat.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

use Rx\Observable;

$source = Observable::range(1, 25)
->concat(Observable::range(1, 25));
$source = Observable::range(0, 25)
->concat(Observable::range(0, 25));

return function() use ($source) {
return $source;
Expand Down
4 changes: 2 additions & 2 deletions benchmark/concat/concat_eventloop.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
$loop = new StreamSelectLoop();
$scheduler = new EventLoopScheduler($loop);

$source = Observable::range(1, 25, $scheduler)
->concat(Observable::range(1, 25, $scheduler));
$source = Observable::range(0, 25, $scheduler)
->concat(Observable::range(0, 25, $scheduler));

$factory = function() use ($source) {
return $source;
Expand Down
10 changes: 10 additions & 0 deletions benchmark/defaultIfEmpty/defaultIfEmpty.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

use Rx\Observable;

$source = Observable::emptyObservable()
->defaultIfEmpty(Observable::just(25));

return function() use ($source) {
return $source;
};
9 changes: 4 additions & 5 deletions benchmark/distinct/distinct.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

use Rx\Observable;

$range = array_map(function($val) {
return $val % 3;
}, range(0, 25));

$source = Observable::fromArray($range)
$source = Observable::range(0, 25)
->map(function($i) {
return $i % 3;
})
->distinct();

return function() use ($source) {
Expand Down
9 changes: 4 additions & 5 deletions benchmark/distinct/distinct_eventloop.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@
$loop = new StreamSelectLoop();
$scheduler = new EventLoopScheduler($loop);

$range = array_map(function($val) {
return $val % 3;
}, range(0, 25));

$source = (new ArrayObservable($range, $scheduler))
$source = Observable::range(0, 25, $scheduler)
->map(function($i) {
return $i % 3;
})
->distinct();

$factory = function() use ($source) {
Expand Down
15 changes: 15 additions & 0 deletions benchmark/forkJoin/forkJoin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

use Rx\Observable;

$source = Observable::defer(function() {
return Observable::forkJoin([
Observable::just(25),
Observable::range(0, 25),
Observable::fromArray(([1, 2, 3, 4, 5]))
]);
});

return function() use ($source) {
return $source;
};
15 changes: 15 additions & 0 deletions benchmark/groupBy/groupBy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

use Rx\Observable;

$source = Observable::range(0, 25)
->map(function($i) {
return ['key' => $i % 5];
})
->groupBy(function($item) {
return $item['key'];
});

return function() use ($source) {
return $source;
};
22 changes: 22 additions & 0 deletions benchmark/groupBy/groupBy_eventloop.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

use Rx\Observable;
use Rx\Scheduler\EventLoopScheduler;
use React\EventLoop\StreamSelectLoop;

$loop = new StreamSelectLoop();
$scheduler = new EventLoopScheduler($loop);

$source = Observable::range(0, 25, $scheduler)
->map(function($i) {
return ['key' => $i % 5];
})
->groupBy(function($item) {
return $item['key'];
});

$factory = function() use ($source) {
return $source;
};

return [$factory, $loop];
10 changes: 10 additions & 0 deletions benchmark/isEmpty/isEmpty.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

use Rx\Observable;

$source = Observable::just(25)
->isEmpty();

return function() use ($source) {
return $source;
};
4 changes: 2 additions & 2 deletions benchmark/merge/merge.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

use Rx\Observable;

$source = Observable::range(1, 25)
->merge(Observable::range(1, 25));
$source = Observable::range(0, 25)
->merge(Observable::range(0, 25));

return function() use ($source) {
return $source;
Expand Down
4 changes: 2 additions & 2 deletions benchmark/merge/merge_eventloop.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
$loop = new StreamSelectLoop();
$scheduler = new EventLoopScheduler($loop);

$source = Observable::range(0, 250, $scheduler)
->merge(Observable::range(0, 250, $scheduler));
$source = Observable::range(0, 25, $scheduler)
->merge(Observable::range(0, 25, $scheduler));

$factory = function() use ($source) {
return $source;
Expand Down
6 changes: 3 additions & 3 deletions benchmark/mergeAll/mergeAll_eventloop.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
$loop = new StreamSelectLoop();
$scheduler = new EventLoopScheduler($loop);

$source = Observable::range(0, 25)
->map(function() {
return Observable::range(0, 25);
$source = Observable::range(0, 25, $scheduler)
->map(function() use ($scheduler) {
return Observable::range(0, 25, $scheduler);
})
->mergeAll();

Expand Down
10 changes: 10 additions & 0 deletions benchmark/pluck/pluck.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

use Rx\Observable;

$source = Observable::just([1, 2, 3, 4, 5])
->pluck(2);

return function() use ($source) {
return $source;
};
12 changes: 12 additions & 0 deletions benchmark/reduce/reduce.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

use Rx\Observable;

$source = Observable::range(0, 25)
->reduce(function($a, $b) {
return $a + $b;
});

return function() use ($source) {
return $source;
};
19 changes: 19 additions & 0 deletions benchmark/reduce/reduce_eventloop.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

use Rx\Observable;
use Rx\Scheduler\EventLoopScheduler;
use React\EventLoop\StreamSelectLoop;

$loop = new StreamSelectLoop();
$scheduler = new EventLoopScheduler($loop);

$source = Observable::range(0, 25, $scheduler)
->reduce(function($a, $b) {
return $a + $b;
});

$factory = function() use ($source) {
return $source;
};

return [$factory, $loop];
10 changes: 10 additions & 0 deletions benchmark/repeat/repeat.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

use Rx\Observable;

$source = Observable::range(0, 25)
->repeat(5);

return function() use ($source) {
return $source;
};
17 changes: 17 additions & 0 deletions benchmark/repeat/repeat_eventloop.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

use Rx\Observable;
use Rx\Scheduler\EventLoopScheduler;
use React\EventLoop\StreamSelectLoop;

$loop = new StreamSelectLoop();
$scheduler = new EventLoopScheduler($loop);

$source = Observable::range(0, 25, $scheduler)
->repeat(5);

$factory = function() use ($source) {
return $source;
};

return [$factory, $loop];
19 changes: 19 additions & 0 deletions benchmark/retry/retry.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

use Rx\Observable;

$maxRetryCount = 25;
$newRetryCount = 0;

$source = Observable::range(5, 1)
->flatMap(function($x) use (&$maxRetryCount, &$newRetryCount) {
if (++$newRetryCount < $maxRetryCount - 1) {
return Observable::error(new \Exception('error'));
}
return Observable::just($x);
})
->retry($maxRetryCount);

return function() use ($source) {
return $source;
};
26 changes: 26 additions & 0 deletions benchmark/retry/retry_eventloop.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

use Rx\Observable;
use Rx\Scheduler\EventLoopScheduler;
use React\EventLoop\StreamSelectLoop;

$loop = new StreamSelectLoop();
$scheduler = new EventLoopScheduler($loop);

$maxRetryCount = 25;
$newRetryCount = 0;

$source = Observable::range(5, 1, $scheduler)
->flatMap(function($x) use (&$maxRetryCount, &$newRetryCount) {
if (++$newRetryCount < $maxRetryCount - 1) {
return Observable::error(new \Exception('error'));
}
return Observable::just($x);
})
->retry($maxRetryCount);

$factory = function() use ($source) {
return $source;
};

return [$factory, $loop];
12 changes: 12 additions & 0 deletions benchmark/scan/scan.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

use Rx\Observable;

$source = Observable::range(0, 25)
->scan(function($acc, $x) {
return $x + $x;
});

return function() use ($source) {
return $source;
};
19 changes: 19 additions & 0 deletions benchmark/scan/scan_eventloop.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

use Rx\Observable;
use Rx\Scheduler\EventLoopScheduler;
use React\EventLoop\StreamSelectLoop;

$loop = new StreamSelectLoop();
$scheduler = new EventLoopScheduler($loop);

$source = Observable::range(0, 25, $scheduler)
->scan(function($acc, $x) {
return $x + $x;
});

$factory = function() use ($source) {
return $source;
};

return [$factory, $loop];
10 changes: 10 additions & 0 deletions benchmark/skip/skip.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

use Rx\Observable;

$source = Observable::range(0, 50)
->skip(25);

return function() use ($source) {
return $source;
};
Loading

0 comments on commit 02f79e4

Please sign in to comment.