getMethods(); $constructor = $reflection->getConstructor(); if ($constructor) { $params = $constructor->getParameters(); } } $nativeTime = microtime(true) - $start; $nativeTimeMs = ($nativeTime * 1000); $nativeTimePerOp = ($nativeTimeMs / $iterations); echo "1. Native ReflectionClass:\n"; echo " Total: " . round($nativeTimeMs, 2) . " ms\n"; echo " Per operation: " . round($nativeTimePerOp, 4) . " ms\n"; echo " Per operation: " . round($nativeTimePerOp * 1000, 2) . " microseconds\n\n"; // Test 2: Native ReflectionMethod (most common operation) $start = microtime(true); for ($i = 0; $i < $iterations; $i++) { $reflection = new ReflectionMethod($className, 'testMethod'); $params = $reflection->getParameters(); foreach ($params as $param) { $type = $param->getType(); $name = $param->getName(); $hasDefault = $param->isDefaultValueAvailable(); } } $nativeMethodTime = microtime(true) - $start; $nativeMethodTimeMs = ($nativeMethodTime * 1000); $nativeMethodTimePerOp = ($nativeMethodTimeMs / $iterations); echo "2. Native ReflectionMethod (getParameters):\n"; echo " Total: " . round($nativeMethodTimeMs, 2) . " ms\n"; echo " Per operation: " . round($nativeMethodTimePerOp, 4) . " ms\n"; echo " Per operation: " . round($nativeMethodTimePerOp * 1000, 2) . " microseconds\n\n"; // Test 3: Cached ReflectionProvider (first run - no cache) $provider = new CachedReflectionProvider(); $classNameObj = ClassName::create($className); $start = microtime(true); for ($i = 0; $i < $iterations; $i++) { $class = $provider->getClass($classNameObj); $methods = $provider->getMethods($classNameObj); $params = $provider->getMethodParameters($classNameObj, '__construct'); } $cachedFirstTime = microtime(true) - $start; $cachedFirstTimeMs = ($cachedFirstTime * 1000); $cachedFirstTimePerOp = ($cachedFirstTimeMs / $iterations); echo "3. Cached ReflectionProvider (first run - no cache):\n"; echo " Total: " . round($cachedFirstTimeMs, 2) . " ms\n"; echo " Per operation: " . round($cachedFirstTimePerOp, 4) . " ms\n"; echo " Per operation: " . round($cachedFirstTimePerOp * 1000, 2) . " microseconds\n\n"; // Test 4: Cached ReflectionProvider (cached - second run) $start = microtime(true); for ($i = 0; $i < $iterations; $i++) { $class = $provider->getClass($classNameObj); $methods = $provider->getMethods($classNameObj); $params = $provider->getMethodParameters($classNameObj, '__construct'); } $cachedSecondTime = microtime(true) - $start; $cachedSecondTimeMs = ($cachedSecondTime * 1000); $cachedSecondTimePerOp = ($cachedSecondTimeMs / $iterations); echo "4. Cached ReflectionProvider (cached - second run):\n"; echo " Total: " . round($cachedSecondTimeMs, 2) . " ms\n"; echo " Per operation: " . round($cachedSecondTimePerOp, 4) . " ms\n"; echo " Per operation: " . round($cachedSecondTimePerOp * 1000, 2) . " microseconds\n\n"; // Comparison echo "=== Comparison ===\n"; $speedup = $nativeTimePerOp / $cachedSecondTimePerOp; echo "Speedup (cached vs native): " . round($speedup, 2) . "x\n"; echo "Overhead (cached first vs native): " . round(($cachedFirstTimePerOp / $nativeTimePerOp - 1) * 100, 1) . "%\n\n"; // Reality check: How many reflection calls per request? echo "=== Reality Check ===\n"; echo "Typical request might call getMethodParameters() 10-50 times\n"; echo "Native: " . round($nativeMethodTimePerOp * 50, 2) . " ms for 50 calls\n"; echo "Cached: " . round($cachedSecondTimePerOp * 50, 2) . " ms for 50 calls\n"; echo "Difference: " . round(($nativeMethodTimePerOp - $cachedSecondTimePerOp) * 50, 2) . " ms\n"; echo "Is this significant? " . (($nativeMethodTimePerOp - $cachedSecondTimePerOp) * 50 > 1 ? "YES (>1ms)" : "NO (<1ms)") . "\n";