MediaWiki REL1_33
TimingTest.php
Go to the documentation of this file.
1<?php
22class TimingTest extends PHPUnit\Framework\TestCase {
23
24 use MediaWikiCoversValidator;
25
30 public function testClearMarks() {
31 $timing = new Timing;
32 $this->assertCount( 1, $timing->getEntries() );
33
34 $timing->mark( 'a' );
35 $timing->mark( 'b' );
36 $this->assertCount( 3, $timing->getEntries() );
37
38 $timing->clearMarks( 'a' );
39 $this->assertNull( $timing->getEntryByName( 'a' ) );
40 $this->assertNotNull( $timing->getEntryByName( 'b' ) );
41
42 $timing->clearMarks();
43 $this->assertCount( 1, $timing->getEntries() );
44 }
45
50 public function testMark() {
51 $timing = new Timing;
52 $timing->mark( 'a' );
53
54 $entry = $timing->getEntryByName( 'a' );
55 $this->assertEquals( 'a', $entry['name'] );
56 $this->assertEquals( 'mark', $entry['entryType'] );
57 $this->assertArrayHasKey( 'startTime', $entry );
58 $this->assertEquals( 0, $entry['duration'] );
59
60 usleep( 100 );
61 $timing->mark( 'a' );
62 $newEntry = $timing->getEntryByName( 'a' );
63 $this->assertGreaterThan( $entry['startTime'], $newEntry['startTime'] );
64 }
65
69 public function testMeasure() {
70 $timing = new Timing;
71
72 $timing->mark( 'a' );
73 usleep( 100 );
74 $timing->mark( 'b' );
75
76 $a = $timing->getEntryByName( 'a' );
77 $b = $timing->getEntryByName( 'b' );
78
79 $timing->measure( 'a_to_b', 'a', 'b' );
80
81 $entry = $timing->getEntryByName( 'a_to_b' );
82 $this->assertEquals( 'a_to_b', $entry['name'] );
83 $this->assertEquals( 'measure', $entry['entryType'] );
84 $this->assertEquals( $a['startTime'], $entry['startTime'] );
85 $this->assertEquals( $b['startTime'] - $a['startTime'], $entry['duration'] );
86 }
87
91 public function testGetEntriesByType() {
92 $timing = new Timing;
93
94 $timing->mark( 'mark_a' );
95 usleep( 100 );
96 $timing->mark( 'mark_b' );
97 usleep( 100 );
98 $timing->mark( 'mark_c' );
99
100 $timing->measure( 'measure_a', 'mark_a', 'mark_b' );
101 $timing->measure( 'measure_b', 'mark_b', 'mark_c' );
102
103 $marks = array_map( function ( $entry ) {
104 return $entry['name'];
105 }, $timing->getEntriesByType( 'mark' ) );
106
107 $this->assertEquals( [ 'requestStart', 'mark_a', 'mark_b', 'mark_c' ], $marks );
108
109 $measures = array_map( function ( $entry ) {
110 return $entry['name'];
111 }, $timing->getEntriesByType( 'measure' ) );
112
113 $this->assertEquals( [ 'measure_a', 'measure_b' ], $measures );
114 }
115}
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
testMark()
Timing::mark Timing::getEntryByName.
testGetEntriesByType()
Timing::getEntriesByType.
testClearMarks()
Timing::clearMarks Timing::getEntries.
testMeasure()
Timing::measure.
An interface to help developers measure the performance of their applications.
Definition Timing.php:45
mark( $markName)
Store a timestamp with the associated name (a "mark")
Definition Timing.php:75