Skip to content
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

Benchmark 2.x #138

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
11 changes: 11 additions & 0 deletions benchmark/bufferWithCount/bufferWithCount.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

use Rx\Observable;
use Rx\Scheduler\ImmediateScheduler;

$source = Observable::range(0, 25, new ImmediateScheduler())
->bufferWithCount(5);

return function() use ($source) {
return $source;
};
17 changes: 17 additions & 0 deletions benchmark/bufferWithCount/bufferWithCount_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)
->bufferWithCount(5);

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

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

use Rx\Observable;
use Rx\Scheduler\ImmediateScheduler;

$scheduler = new ImmediateScheduler();

$source = Observable::error(new \Exception('error'), $scheduler)
->catch(function() use ($scheduler) {
return Observable::of(25, $scheduler);
});

return function() use ($source) {
return $source;
};
17 changes: 17 additions & 0 deletions benchmark/catch/catch_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::error(new \Exception('error'), $scheduler)
->catch(function() use ($scheduler) {
return Observable::of(25, $scheduler);
});

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

use Rx\Observable;
use Rx\Scheduler\ImmediateScheduler;

$scheduler = new ImmediateScheduler();

$source = Observable::range(0, 25, $scheduler)
->combineLatest([Observable::range(0, 25, $scheduler)], 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];
13 changes: 13 additions & 0 deletions benchmark/concat/concat.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

use Rx\Observable;
use Rx\Scheduler\ImmediateScheduler;

$scheduler = new ImmediateScheduler();

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

return function() use ($source) {
return $source;
};
17 changes: 17 additions & 0 deletions benchmark/concat/concat_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)
->concat(Observable::range(0, 25, $scheduler));

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

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

use Rx\Observable;
use Rx\Scheduler\ImmediateScheduler;

$scheduler = new ImmediateScheduler();

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

return function() use ($source) {
return $source;
};
20 changes: 20 additions & 0 deletions benchmark/concatAll/concatAll_eventloop.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?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() use ($scheduler) {
return Observable::range(0, 25, $scheduler);
})
->concatAll();

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

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

use Rx\Observable;
use Rx\Scheduler\ImmediateScheduler;

$scheduler = new ImmediateScheduler();

$source = Observable::range(1, 25, $scheduler)
->concatMap(function($x) use ($scheduler) {
return Observable::range($x, 25, $scheduler);
});

return function() use ($source) {
return $source;
};
19 changes: 19 additions & 0 deletions benchmark/concatMap/concatMap_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(1, 25, $scheduler)
->concatMap(function($x) use ($scheduler) {
return Observable::range($x, 25, $scheduler);
});

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

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

use Rx\Observable;
use Rx\Scheduler\ImmediateScheduler;

$scheduler = new ImmediateScheduler();

$source = Observable::empty($scheduler)
->defaultIfEmpty(Observable::of(25, $scheduler));

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

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

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

$source = Observable::empty($scheduler)
->defaultIfEmpty(Observable::of(25, $scheduler));

return function() use ($source) {
return $source;
};
17 changes: 17 additions & 0 deletions benchmark/delay/delay_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::of(25, $scheduler)
->delay(0, $scheduler);

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

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

use Rx\Observable;
use Rx\Scheduler\ImmediateScheduler;

$scheduler = new ImmediateScheduler();

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

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

use Rx\Observable;
use Rx\Observable\ArrayObservable;
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 $i % 3;
})
->distinct();

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

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

use Rx\Observable;
use Rx\Scheduler\ImmediateScheduler;

$scheduler = new ImmediateScheduler();

$source = Observable::range(0, 50, $scheduler)
->filter(function($value) {
return $value % 2 == 0;
})
->filter(function($value) {
return $value % 10 == 0;
});

return function() use ($source) {
return $source;
};
22 changes: 22 additions & 0 deletions benchmark/filter/filter_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, 50, $scheduler)
->filter(function($value) {
return $value % 2 == 0;
})
->filter(function($value) {
return $value % 10 == 0;
});

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

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

use Rx\Observable;
use Rx\Scheduler\ImmediateScheduler;

$scheduler = new ImmediateScheduler();

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

return function() use ($source) {
return $source;
};
19 changes: 19 additions & 0 deletions benchmark/flatMap/flatMap_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)
->flatMap(function($x) use ($scheduler) {
return Observable::range($x, 25, $scheduler);
});

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

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

use Rx\Observable;
use Rx\Scheduler\ImmediateScheduler;

$scheduler = new ImmediateScheduler();

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

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