summaryrefslogtreecommitdiffstats
path: root/tests/codeigniter/core/Benchmark_test.php
blob: 109b388210f7027cddf5fe96acefe98eb7864d12 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php

class Benchmark_test extends CI_TestCase {
	
	public function set_up()
	{
		$this->benchmark = new Mock_Core_Benchmark();
	}
	
	// --------------------------------------------------------------------
	
	public function test_mark()
	{
		$this->assertEmpty($this->benchmark->marker);

		$this->benchmark->mark('code_start');

		$this->assertEquals(1, count($this->benchmark->marker));
		$this->assertArrayHasKey('code_start', $this->benchmark->marker);
	}
	
	// --------------------------------------------------------------------

	public function test_elapsed_time()
	{
		$this->assertEquals('{elapsed_time}', $this->benchmark->elapsed_time());
		$this->assertEmpty($this->benchmark->elapsed_time('undefined_point'));

		$this->benchmark->mark('code_start');
		sleep(1);
		$this->benchmark->mark('code_end');
		
		$this->assertEquals('1.0', $this->benchmark->elapsed_time('code_start', 'code_end', 1));
	}

	// --------------------------------------------------------------------

	public function test_memory_usage()
	{
		$this->assertEquals('{memory_usage}', $this->benchmark->memory_usage());
	}
}