# Posted By

iTony on 10/26/08

# Statistics

Viewed 321 times
Favorited by 1 user(s)

# Benchmark function for php

/ Published in: PHP `<?php/** Function: benchmark* Author: Michael Bailey <[email protected]>* Date: 5 Dec 2002* License: GPL (General Public License)* Purpose: This function will run the line of code* sent as the first parameter and return* the time it took to complete execution.* If a second parameter is passed, the* function will run the code the specified* number of times, taking the average. This* will return a better approximation. The* last parameter allows you to send code to* be executed between iterations, in case* something needs to be reset (ie. global* variables, etc...). The function returns* the number of seconds* with a bunch of decimal places.*/function benchmark(\$code, \$iter = 1, \$reset_code = null){# Determine the overhead in calling the eval function# You might want to to this multiple times to get better# precision.\$start = microtime();eval("");\$end = microtime();list(\$start_ms, \$start_s) = explode(" ", \$start);list(\$end_ms, \$end_s) = explode(" ", \$end);\$overhead = (\$end_ms+\$end_s) - (\$start_ms+\$start_s); # Execute the code the specified number of timesfor (\$i=0; \$i<\$iter; \$i++) {\$start = microtime();eval(\$code);\$end = microtime();list(\$start_ms, \$start_s) = explode(" ", \$start);list(\$end_ms, \$end_s) = explode(" ", \$end);\$time += (\$end_ms+\$end_s) - (\$start_ms+\$start_s); # If reset code was specified, evaluate itif (\$reset_code != null) eval(\$reset_code);} # Return the average speed subtracted by# the overhead of calling eval()return (\$time/\$iter) - \$overhead;}?>` Subscribe to comments
{"ft_lang_label":"__label__en","ft_lang_prob":0.6109929,"math_prob":0.95011115,"size":1669,"snap":"2021-43-2021-49","text_gpt3_token_len":452,"char_repetition_ratio":0.112912916,"word_repetition_ratio":0.026666667,"special_character_ratio":0.3289395,"punctuation_ratio":0.1557971,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9781164,"pos_list":[0,1,2,3,4,5,6],"im_url_duplicate_count":[null,null,null,null,null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-10-19T10:03:44Z\",\"WARC-Record-ID\":\"<urn:uuid:55460052-0a55-4dc7-8b2e-66f963338e26>\",\"Content-Length\":\"33008\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:5f7206a6-2b06-4788-aa3d-9578bead2ba7>\",\"WARC-Concurrent-To\":\"<urn:uuid:13bfa44e-c5e3-4be5-abee-1ad15a5d09b8>\",\"WARC-IP-Address\":\"104.25.40.44\",\"WARC-Target-URI\":\"https://snipplr.com/view/9270/benchmark-function-for-php\",\"WARC-Payload-Digest\":\"sha1:ZQ7WLKWSHQTU6CH3WEEF4SRTAGJ43PBM\",\"WARC-Block-Digest\":\"sha1:HXBBKI4LCMIVTCN5GEESXVEKUAGPJPAB\",\"WARC-Identified-Payload-Type\":\"application/xhtml+xml\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-43/CC-MAIN-2021-43_segments_1634323585246.50_warc_CC-MAIN-20211019074128-20211019104128-00266.warc.gz\"}"}