Created
April 25, 2017 20:02
-
-
Save thekid/825bbb7bf142476d614022176755ee1d to your computer and use it in GitHub Desktop.
Performance profiling for xp-forge/sequence
This file contains hidden or 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
| <?php | |
| use util\data\Sequence; | |
| class Operations extends \util\profiling\Measurable { | |
| private static $range; | |
| static function __static() { | |
| self::$range= range(0, 9999); | |
| } | |
| #[@measure] | |
| public function filter() { | |
| return Sequence::of(self::$range) | |
| ->filter(function($_) { return 0 === $_ % 2; }) | |
| ->each() | |
| ; | |
| } | |
| #[@measure] | |
| public function map() { | |
| return Sequence::of(self::$range) | |
| ->map(function($_) { return $_ * 2; }) | |
| ->each() | |
| ; | |
| } | |
| #[@measure] | |
| public function peek() { | |
| return Sequence::of(self::$range) | |
| ->peek(function($_) { /* NOOP */ }) | |
| ->each() | |
| ; | |
| } | |
| #[@measure] | |
| public function flatten() { | |
| return Sequence::of(self::$range) | |
| ->flatten(function($_) { return [$_, $_ * 2]; }) | |
| ->each() | |
| ; | |
| } | |
| #[@measure] | |
| public function skip_n() { | |
| return Sequence::of(self::$range) | |
| ->skip(1000) | |
| ->each() | |
| ; | |
| } | |
| #[@measure] | |
| public function skip() { | |
| return Sequence::of(self::$range) | |
| ->skip(function($_) { return $_ < 1000; }) | |
| ->each() | |
| ; | |
| } | |
| #[@measure] | |
| public function limit_n() { | |
| return Sequence::of(self::$range) | |
| ->limit(9000) | |
| ->each() | |
| ; | |
| } | |
| #[@measure] | |
| public function limit() { | |
| return Sequence::of(self::$range) | |
| ->limit(function($_) { return $_ >= 9000; }) | |
| ->each() | |
| ; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment