File tree 7 files changed +78
-19
lines changed
7 files changed +78
-19
lines changed Original file line number Diff line number Diff line change 26
26
dependencies :
27
27
- lowest
28
28
- highest
29
- include :
30
- - php : ' 8.1'
31
- dependencies : lowest
32
29
33
30
steps :
34
31
- name : Checkout
75
72
uses : codecov/codecov-action@v1
76
73
with :
77
74
file : build/coverage-report.xml
75
+
76
+ - name : Check benchmarks
77
+ run : vendor/bin/phpbench run --revs=1 --iterations=1
78
+ if : ${{ matrix.dependencies == 'highest' && matrix.php == '8.1' }}
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ package.xml
3
3
/vendor
4
4
.idea
5
5
.php-cs-fixer.cache
6
+ .phpbench
6
7
.phpunit.result.cache
7
8
docs /_build
8
9
tests /clover.xml
Original file line number Diff line number Diff line change 2
2
3
3
## Unreleased
4
4
5
+ - Optimize ` Span ` constructor and add benchmarks (#1274 )
6
+
5
7
## 3.3.5 (2021-12-27)
6
8
7
9
- Bump the minimum required version of the ` jean85/pretty-package-versions ` package (#1267 )
Original file line number Diff line number Diff line change 44
44
"monolog/monolog" : " ^1.3|^2.0" ,
45
45
"nikic/php-parser" : " ^4.10.3" ,
46
46
"php-http/mock-client" : " ^1.3" ,
47
+ "phpbench/phpbench" : " ^1.0" ,
47
48
"phpstan/extension-installer" : " ^1.0" ,
48
49
"phpstan/phpstan" : " ^1.3" ,
49
50
"phpstan/phpstan-phpunit" : " ^1.0" ,
Original file line number Diff line number Diff line change
1
+ {
2
+ "$schema" :" ./vendor/phpbench/phpbench/phpbench.schema.json" ,
3
+ "runner.bootstrap" : " vendor/autoload.php" ,
4
+ "runner.retry_threshold" : 2 ,
5
+ "runner.path" : " tests/Benchmark"
6
+ }
Original file line number Diff line number Diff line change @@ -80,26 +80,17 @@ class Span
80
80
*/
81
81
public function __construct (?SpanContext $ context = null )
82
82
{
83
- $ this ->traceId = TraceId::generate ();
84
- $ this ->spanId = SpanId::generate ();
85
- $ this ->startTimestamp = microtime (true );
86
-
87
83
if (null === $ context ) {
88
- return ;
89
- }
90
-
91
- if (null !== $ context ->getTraceId ()) {
92
- $ this ->traceId = $ context ->getTraceId ();
93
- }
94
-
95
- if (null !== $ context ->getSpanId ()) {
96
- $ this ->spanId = $ context ->getSpanId ();
97
- }
84
+ $ this ->traceId = TraceId::generate ();
85
+ $ this ->spanId = SpanId::generate ();
86
+ $ this ->startTimestamp = microtime (true );
98
87
99
- if (null !== $ context ->getStartTimestamp ()) {
100
- $ this ->startTimestamp = $ context ->getStartTimestamp ();
88
+ return ;
101
89
}
102
90
91
+ $ this ->traceId = $ context ->getTraceId () ?? TraceId::generate ();
92
+ $ this ->spanId = $ context ->getSpanId () ?? SpanId::generate ();
93
+ $ this ->startTimestamp = $ context ->getStartTimestamp () ?? microtime (true );
103
94
$ this ->parentSpanId = $ context ->getParentSpanId ();
104
95
$ this ->description = $ context ->getDescription ();
105
96
$ this ->op = $ context ->getOp ();
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ declare (strict_types=1 );
4
+
5
+ namespace Sentry \Tests \Benchmark ;
6
+
7
+ use PhpBench \Benchmark \Metadata \Annotations \Iterations ;
8
+ use PhpBench \Benchmark \Metadata \Annotations \Revs ;
9
+ use Sentry \Tracing \Span ;
10
+ use Sentry \Tracing \TransactionContext ;
11
+
12
+ final class SpanBench
13
+ {
14
+ /**
15
+ * @var TransactionContext
16
+ */
17
+ private $ context ;
18
+
19
+ /**
20
+ * @var TransactionContext
21
+ */
22
+ private $ contextWithTimestamp ;
23
+
24
+ public function __construct ()
25
+ {
26
+ $ this ->context = TransactionContext::fromSentryTrace ('566e3688a61d4bc888951642d6f14a19-566e3688a61d4bc8-0 ' );
27
+ $ this ->contextWithTimestamp = TransactionContext::fromSentryTrace ('566e3688a61d4bc888951642d6f14a19-566e3688a61d4bc8-0 ' );
28
+ $ this ->contextWithTimestamp ->setStartTimestamp (microtime (true ));
29
+ }
30
+
31
+ /**
32
+ * @Revs(100000)
33
+ * @Iterations(10)
34
+ */
35
+ public function benchConstructor (): void
36
+ {
37
+ $ span = new Span ();
38
+ }
39
+
40
+ /**
41
+ * @Revs(100000)
42
+ * @Iterations(10)
43
+ */
44
+ public function benchConstructorWithInjectedContext (): void
45
+ {
46
+ $ span = new Span ($ this ->context );
47
+ }
48
+
49
+ /**
50
+ * @Revs(100000)
51
+ * @Iterations(10)
52
+ */
53
+ public function benchConstructorWithInjectedContextAndStartTimestamp (): void
54
+ {
55
+ $ span = new Span ($ this ->contextWithTimestamp );
56
+ }
57
+ }
You can’t perform that action at this time.
0 commit comments