<?php

class Test {
	public $amplitude = 0;
	public $sin_dict = [0 => 0.00, 1 => 0.10, 2 => 0.20, 3 => 0.29, 4 => 0.38, 5 => 0.47, 6 => 0.56, 7 => 0.63, 8 => 0.71, 9 => 0.77, 10 => 0.83, 11 => 0.88, 12 => 0.92, 13 => 0.96, 14 => 0.98, 15 => 0.10];
	public $sin_list = [0.00, 0.10, 0.20, 0.29, 0.38, 0.47, 0.56, 0.63, 0.71, 0.77, 0.83, 0.88, 0.92, 0.96, 0.98, 0.10];

	public function test_ref($i) {
		$this->amplitude += $i;
	}

	public function test_if($i) {
		if($i == 0)
			$this->amplitude += 0.00;
		else if ($i == 1)
			$this->amplitude += 0.10;
		else if ($i == 2)
			$this->amplitude += 0.20;
		else if ($i == 3)
			$this->amplitude += 0.29;
		else if ($i == 4)
			$this->amplitude += 0.38;
		else if ($i == 5)
			$this->amplitude += 0.47;
		else if ($i == 6)
			$this->amplitude += 0.56;
		else if ($i == 7)
			$this->amplitude += 0.63;
		else if ($i == 8)
			$this->amplitude += 0.71;
		else if ($i == 9)
			$this->amplitude += 0.77;
		else if ($i == 10)
			$this->amplitude += 0.83;
		else if ($i == 11)
			$this->amplitude += 0.88;
		else if ($i == 12)
			$this->amplitude += 0.92;
		else if ($i == 13)
			$this->amplitude += 0.96;
		else if ($i == 14)
			$this->amplitude += 0.98;
		else if ($i == 15)
			$this->amplitude += 0.10;
		else
			$this->amplitude += 0.00;
	}

	function test_dict($i) {
		if (isset($this->dict[$i])) {
			$this->amplitude += $this->sin_dict[$i];
		}
	}

	function test_list($i) {
		$this->amplitude += $this->sin_list[$i];
	}

	public function test_switch($i) {
		switch ($i) {
			case 0:
				$this->amplitude += 0.00;
				break;
			case 1:
				$this->amplitude += 0.10;
				break;
			case 2:
				$this->amplitude += 0.20;
				break;
			case 3:
				$this->amplitude += 0.29;
				break;
			case 4:
				$this->amplitude += 0.38;
				break;
			case 5:
				$this->amplitude += 0.47;
				break;
			case 6:
				$this->amplitude += 0.56;
				break;
			case 7:
				$this->amplitude += 0.63;
				break;
			case 8:
				$this->amplitude += 0.71;
				break;
			case 9:
				$this->amplitude += 0.77;
				break;
			case 10:
				$this->amplitude += 0.83;
				break;
			case 11:
				$this->amplitude += 0.88;
				break;
			case 12:
				$this->amplitude += 0.92;
				break;
			case 13:
				$this->amplitude += 0.96;
				break;
			case 14:
				$this->amplitude += 0.98;
				break;
			case 15:
				$this->amplitude += 0.10;
				break;
			default:
				break;
		}
	}
}

$test = new Test();

function test_ref() {
	global $test;
	for ($j = 0; $j < 100000; ++$j) {
		for ($i = 0; $i < 16; ++$i) {
			$test->test_ref($i);
		}
	}
}

function test_if() {
	global $test;
	for ($j = 0; $j < 100000; ++$j) {
		for ($i = 0; $i < 16; ++$i) {
			$test->test_if($i);
		}
	}
}

function test_dict() {
	global $test;
	for ($j = 0; $j < 100000; ++$j) {
		for ($i = 0; $i < 16; ++$i) {
			$test->test_dict($i);
		}
	}
}

function test_list() {
	global $test;
	for ($j = 0; $j < 100000; ++$j) {
		for ($i = 0; $i < 16; ++$i) {
			$test->test_dict($i);
		}
	}
}

function test_switch() {
	global $test;
	for ($j = 0; $j < 100000; ++$j) {
		for ($i = 0; $i < 16; ++$i) {
			$test->test_dict($i);
		}
	}
}

function measure($fun) {
	global $test;
	$test->amplitude = 0;
	$start = microtime(true);
	call_user_func($fun);
	$time_elapsed = microtime(true) - $start;
	echo $fun . " " . $time_elapsed . "\n";
}

measure("test_ref");
measure("test_if");
measure("test_dict");
measure("test_list");
measure("test_switch");

?>
