Skip to content

Instantly share code, notes, and snippets.

@thekid
Created April 25, 2017 20:02
Show Gist options
  • Select an option

  • Save thekid/825bbb7bf142476d614022176755ee1d to your computer and use it in GitHub Desktop.

Select an option

Save thekid/825bbb7bf142476d614022176755ee1d to your computer and use it in GitHub Desktop.
Performance profiling for xp-forge/sequence
<?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