File tree 2 files changed +21
-6
lines changed
src/Symfony/Component/Stopwatch
2 files changed +21
-6
lines changed Original file line number Diff line number Diff line change @@ -177,12 +177,10 @@ public function getEndTime()
177
177
public function getDuration ()
178
178
{
179
179
$ periods = $ this ->periods ;
180
- $ stopped = \count ($ periods );
181
- $ left = \count ($ this ->started ) - $ stopped ;
180
+ $ left = \count ($ this ->started );
182
181
183
- for ($ i = 0 ; $ i < $ left ; ++$ i ) {
184
- $ index = $ stopped + $ i ;
185
- $ periods [] = new StopwatchPeriod ($ this ->started [$ index ], $ this ->getNow (), $ this ->morePrecision );
182
+ for ($ i = $ left - 1 ; $ i >= 0 ; --$ i ) {
183
+ $ periods [] = new StopwatchPeriod ($ this ->started [$ i ], $ this ->getNow (), $ this ->morePrecision );
186
184
}
187
185
188
186
$ total = 0 ;
Original file line number Diff line number Diff line change @@ -99,8 +99,25 @@ public function testDurationBeforeStop()
99
99
$ event ->stop ();
100
100
usleep (50000 );
101
101
$ event ->start ();
102
- usleep (100000 );
103
102
$ this ->assertEqualsWithDelta (100 , $ event ->getDuration (), self ::DELTA );
103
+ usleep (100000 );
104
+ $ this ->assertEqualsWithDelta (200 , $ event ->getDuration (), self ::DELTA );
105
+ }
106
+
107
+ public function testDurationWithMultipleStarts ()
108
+ {
109
+ $ event = new StopwatchEvent (microtime (true ) * 1000 );
110
+ $ event ->start ();
111
+ usleep (100000 );
112
+ $ event ->start ();
113
+ usleep (100000 );
114
+ $ this ->assertEqualsWithDelta (300 , $ event ->getDuration (), self ::DELTA );
115
+ $ event ->stop ();
116
+ $ this ->assertEqualsWithDelta (300 , $ event ->getDuration (), self ::DELTA );
117
+ usleep (100000 );
118
+ $ this ->assertEqualsWithDelta (400 , $ event ->getDuration (), self ::DELTA );
119
+ $ event ->stop ();
120
+ $ this ->assertEqualsWithDelta (400 , $ event ->getDuration (), self ::DELTA );
104
121
}
105
122
106
123
public function testStopWithoutStart ()
You can’t perform that action at this time.
0 commit comments