您的位置:首页 > 数据库 > MySQL

MySQL--BENCHMARK()函数

2016-03-03 19:45 609 查看

说明

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》
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: