MySQL--BENCHMARK()函数

来源:互联网 发布:mv软件 编辑:程序博客网 时间:2024/05/18 00:37

说明

MySQL有一个内置的BENCHMARK()函数,可以测试某些特定操作的执行速度。
参数可以是需要执行的次数和表达式。
表达式可以是任何的标量表达式,比如返回值是标量的子查询或者函数。

请注意:该函数只是简单地返回服务器执行表达式的时间,而不会涉及分析和优化的开销。

该函数可以很方便地测试某些特定操作的性能,比如通过测试可以发现,MD5()比SHA1()函数要快:

试验结果

mysql> SET @input := “hello world”;
Query OK, 0 rows affected (0.00 sec)

mysql> select @input;
+————-+
| @input |
+————-+
| hello world |
+————-+
1 row in set (0.00 sec)

mysql> select @a;
+——+
| @a |
+——+
| NULL |
+——+
1 row in set (0.00 sec)

mysql> select BENCHMARK(10000000,MD5(@input));
+———————————+
| BENCHMARK(10000000,MD5(@input)) |
+———————————+
| 0 |
+———————————+
1 row in set (3.40 sec)

mysql> select BENCHMARK(10000000,SHA1(@input));
+———————————-+
| BENCHMARK(10000000,SHA1(@input)) |
+———————————-+
| 0 |
+———————————-+
1 row in set (6.19 sec)

mysql>

参考文献

《高性能MySQL》

0 0