-3

Here is two function that creates 1000 files inside 1000 folders in two different fashion:

First Method

function createEverything() {
    for($i = 1; $i < 1000; $i++) {
        mkdir('test/'.$i);
        file_put_contents("test/".$i."/".$i.".txt", time());
    }
}

Second Method

function createEverything() {
    for($i = 1; $i < 1000; $i++) {
        exec("mkdir test/".$i);
        exec("touch test/".$i."/".$i.".txt");
        exec("echo ".time()." >> test/".$i."/".$i.".txt");
    }
}

The second method utilized the unix commands in order to create 1000 files inside 1000 folders.
Now my question is it possible to get the CPU information's, RAM uses and other performance related information's separately for this two separate method, so i can compare which one is appropriate for me?

rakibtg
  • 5,521
  • 11
  • 50
  • 73
  • No matter how performant it is, it is a terrible idea to use shell commands if your programming language's stdlib provides the same functionality. Besides that, not having to launch three programs per iteration is pretty much always much faster. Oh, and `$i == 1000` makes no sense. You want `$i < 1000`. Also, this is not an algorithm, it's just plain code. – ThiefMaster Dec 28 '14 at 14:55
  • 2
    possible duplicate of [How to benchmark efficiency of PHP script](http://stackoverflow.com/questions/8291366/how-to-benchmark-efficiency-of-php-script) – andrew Dec 28 '14 at 14:55
  • Thankyou, but it is a demonstration just to let everyone understand what i want to do. – rakibtg Dec 28 '14 at 14:56

1 Answers1

0

try Apache Benchmark (ab / ab.exe). create two files - one for each algorithm also add to each exactly the same code for deleting everything they creates (but the same code should do that).

Then use ab to test each file (separately) for around 100-1000 tries each. (same number for both scripts); Then (because both used same thing for deleting) only creating algorithm should make differences.

Have fun^^

Seti
  • 2,169
  • 16
  • 26
  • Its very EASY way to fast test something. Not necessary best - but do not require anything to install. – Seti Dec 28 '14 at 23:04