MySQL实现了很多独特的函数,有时候使用起来是非常的方便,或许这就是开源的好处吧。这里记录一下benchmark函数,一个用于测试MySQL函数性能的函数。benchmark函数只有两个参数,第一个是执行次数,第二个是要测试的函数或者表达式。返回的结果始终是0,执行时间才是我们需要的结果:
mysql> select benchmark(1e8,current_date()); +——————————-+ | benchmark(1e8,current_date()) | +——————————-+ | 0 | +——————————-+ 1 row in set (31.08 sec)
mysql> select benchmark(1e8,abs(1)); +———————–+ | benchmark(1e8,abs(1)) | +———————–+ | 0 | +———————–+ 1 row in set (1.31 sec)
除法的效率明显不如乘法:
mysql> select benchmark(1e8,1*1); +——————–+ | benchmark(1e8,1*1) | +——————–+ | 0 | +——————–+ 1 row in set (1.45 sec) mysql> select benchmark(1e8,1/1); +——————–+ | benchmark(1e8,1/1) | +——————–+ | 0 | +——————–+ 1 row in set (19.47 sec)
查看更多关于MySQL的benchmark函数使用方法的详细内容...