Please run code for me

For a research, I need to have the result of this code on several servers. I highly appreciate it if you run it on your server, and give the result.

     <?php
     $timeTarget = 0.2;
     $cost = PASSWORD_BCRYPT_DEFAULT_COST;
     do {
         $cost++;
         $start = microtime(true);
         password_hash("test", PASSWORD_DEFAULT, array("cost" => $cost));
         $end = microtime(true);
     } while (($end - $start) < $timeTarget);
     print($cost);

Do a search for “Online PHP Tester” - there are several sandbox type sites which will let you test stuff like this…

2 Likes

I am aware of that, but I need it on actual live servers. It isn’t a pain for others to run just this brief script.

Not much of a pain, true. But relatively useless data would be obtained from others running that snippet.

One variable is “clock” and how a server deals with “drift correction”
Another is “DEFAULT”, a server may have blowfish as the default, but then, it might not.
And the state of the server load could affect how much resource use is allocated to the script at the time it is run.

True, the differences would likely be negligible. At the same time differences would be insignificant. Especially for a DIY benchmark script.

Interesting perhaps, but data of no real value other than maybe as an introductory learning exercise.

IMHO you would better spend your efforts using a true benchmarking script, and focus on improving areas of code that may have a significant impact rather than being concerned with over optimizing a single native PHP function. In my experience things such as complex loop structure and memory leaks are better candidates for optimization than fine tuning native functions.

1 Like

I don’t see what conclusions you would get from these result, you know exactly nothing about the server. not hardware, not if it runs a virtual machine, not even the PHP version which is running, or other processes which use e.g. the CPU. And from the userbase reading this post you may get 10 results. or 100 if you post this on other platforms. all the online PHP test suites ARE live servers.

just use rand().

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.