Benchmark class, release (& first test)

So as promised I’ve cleaned up and commented a bit on my Bench class. And let me get to it, you can

Download it here.

Bench suite

I’ve also made my first test in my new (and not to pretty, but working) bench suite. The bench suite is a site where I can gather my different tests, and be able to easily access them later on for references. So far it’s a very simple setup, where I have:

  • A list of the tests. This goes through a directory where each test has it’s own test file, and use some of the data in the file to make an informative list.
  • A runner. Which will run each test, and output the results in an easy to read table, along with the actual source code of the test.

Down the road I would like to improve a bit on the interface which is lacking to say the least. I’ve also been planning on saving the test data so I can get an average result of all the tests run.

Empty loops test

So the very first test I’ve done is a simple empty loop(it will run the test every time you, so the result wont be identical to what I’ve displayed below) test. And it also works as a quick how-to for the class it self.
What I wanted to test with this bench, was the difference between the for, while and do..while loops, and as an added bonus I also tested a goto loop (more for the fun of things). I’ve also tested everything with a pre and post increment. Anyway the result of the test looks as following after it’s been through google docs:

To reach my conclusion I’ve run the test multiple times (the above chart is just from a single run), and it seems that the do..while is the fastest loop most of the time, followed by the while loop. A thing that I noticed was the for loop runs faster with pre incrementing(++$i) instead of post($i++). But the other loops tend to be faster with a post increment, don’t ask me why it’s just what I’ve observed.
Even though the do..while is notably faster (almost every time) I think I’ll stick to using the for loop for these kind of loops, unless I really need the speed. In case I needed the speed I would probably do a test with each loop to see what gain I actually would get in that specific case.

All in all a good first test, I think I’ll need to test fewer things in my next tests if possible. I could have skipped pre and post incrementing to make the chart a more readable, something I might keep in mind for my next bench.

Leave a Comment

NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>