/** * @covers ::using * @dataProvider provideDataToTest */ public function testCanCallStatically($item, $dispatchTable, $expectedResult) { // ---------------------------------------------------------------- // setup your test // ---------------------------------------------------------------- // perform the change $actualResult = MapStrictTypeToMethodName::using($item, $dispatchTable); // ---------------------------------------------------------------- // test the results $this->assertEquals($expectedResult, $actualResult); }
$method = $cachingTable->mapTypeToMethodName($item); } $endTime = microtime(true); $totalTime = round($endTime - $startTime, 3); echo "[Objects only ] Total time: " . $totalTime . PHP_EOL; // let's compare that with our type-driven caching dispatch table $startTime = microtime(true); $cachingTable = new TypeOnlyDispatchTable($dispatchTable, new MapStrictTypeToMethodName()); for ($i = 0; $i < $maxIterations; $i++) { $method = $cachingTable->mapTypeToMethodName($item); } $endTime = microtime(true); $totalTime = round($endTime - $startTime, 3); echo "[Type only ] Total time: " . $totalTime . PHP_EOL; // let's compare that with our caching dispatch table $startTime = microtime(true); $cachingTable = new AllPurposeDispatchTable($dispatchTable, new MapStrictTypeToMethodName()); for ($i = 0; $i < $maxIterations; $i++) { $method = $cachingTable->mapTypeToMethodName($item); } $endTime = microtime(true); $totalTime = round($endTime - $startTime, 3); echo "[All Purpose ] Total time: " . $totalTime . PHP_EOL; // finally, not using a caching dispatch table at all $startTime = microtime(true); for ($i = 0; $i < $maxIterations; $i++) { $method = MapStrictTypeToMethodName::using($item, $dispatchTable); } $endTime = microtime(true); $totalTime = round($endTime - $startTime, 3); echo "[No cache ] Total time: " . $totalTime . PHP_EOL;