Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/local/bin/php
- <?php
- set_time_limit(0);
- error_reporting(E_ALL);
- ini_set('display_errors', 'on');
- $method1 = array();
- $method2 = array();
- $code = '
- $var1 = "1";
- $var2 = "2";
- if ($var1 == $var2) {
- $var3 = "3";
- } else {
- $var = "4";
- }
- ';
- for ($n = 0; $n < 100000; $n++)
- {
- // Method 1
- $start = microtime(TRUE);
- eval($code);
- $end = microtime(TRUE);
- $method1[] = $end - $start;
- // Method 2
- $start = microtime(TRUE);
- include('data:text/plaintext;base64,'.base64_encode('<?php '.$code));
- $end = microtime(TRUE);
- $method2[] = $end - $start;
- }
- $total1 = 0;
- foreach ($method1 as $count1)
- {
- $total1 += $count1;
- }
- echo "1 (eval): \n";
- echo "Total: {$total1}\n";
- echo 'Median: '.$method1[floor(count($method1) / 2)]."\n\n";
- $total2 = 0;
- foreach ($method2 as $count2)
- {
- $total2 += $count2;
- }
- asort($method2);
- echo "2 (include): \n";
- echo "Total: {$total2}\n";
- echo 'Median: '.$method2[floor(count($method2) / 2)]."\n\n";
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement