Archives

The List

« How to Kill Your Book Sales | Main | MD5() :: MySQL Function of the Day »

BENCHMARK() :: MySQL Function of the Day

By Carsten | April 16, 2008

unction name: BENCHMARK()
Aliases: -
Function type: Information Function
Purpose: Repeat an operation a number of times

Description: BENCHMARK(multiplier, operation) executes operation multiplier times:

mysql> select BENCHMARK(100000, MD5(’bitbybit’));
+————————————+
| benchmark(100000, md5(’bitbybit’)) |
+————————————+
| 0 |
+————————————+
1 row in set (0.40 sec)

The returned result is hardly interesting, as by definition this is always 0. But the last line of the above output, where we see “0.40 sec” is. Here, you can see that it took MySQL .4s to perform the md5(’bitbybit’) operation 100 000 times, or 4µs per iteration.

There are many parameters in benchmarking, including the number of concurrent processes, available RAM, disk speed access, and so fort. In many ways, BENCHMARK() is a fairly crude metric to use. None the less, it’s very useful for making at least rough estimations on how long a given operation is going to take.

You can see a real-world example where BENCHMARK() was used to compare two approaches to string manipulation here.

MySQL manual entry on BENCHMARK()


MySQL Function of the Day is a small series of concise information regarding most of the functions and operators available in MySQL. Inspired by PHPs funcaday, it’s meant to provide a daily dose of something in-between “Aha!” and “Ho-hum, I knew that already”, depending on your level of experience with MySQL. You can access the entire series with your browser here or pick up the RSS feed here.

Topics: MySQL Function of the day |

Comments