Crie dois procedimentos armazenados
- Um para executar uma consulta de sua escolha
- Um para testar o primeiro procedimento armazenado
Instale este banco de dados e os Procedimentos Armazenados
drop database if exists mybmark;
create database mybmark;
use mybmark
DELIMITER $$
DROP PROCEDURE IF EXISTS 'mybmark'.'testproc' $$
CREATE PROCEDURE 'mybmark'.'testproc' ()
BEGIN
DECLARE answer INT;
SELECT 1+2 INTO answer;
END $$
DELIMITER ;
DELIMITER $$
DROP PROCEDURE IF EXISTS 'mybmark'.'mybenchmark' $$
CREATE PROCEDURE 'mybmark'.'mybenchmark' (loop_count INT,expr varchar(128))
BEGIN
DECLARE dt1,dt2,dtdiff,ndx INT;
SET dt1 = UNIX_TIMESTAMP();
SET ndx = loop_count;
SET @sql = expr;
PREPARE stmt FROM @sql;
WHILE ndx > 0 DO
EXECUTE stmt;
SET ndx = ndx - 1;
END WHILE;
DEALLOCATE PREPARE stmt;
SET dt2 = UNIX_TIMESTAMP();
SET dtdiff = dt2 - dt1;
SELECT dt1,dt2,dtdiff;
END $$
DELIMITER ;
O procedimento armazenado mybmark.testproc
acabou de executar um SELECT de uma expressão. Você poderia testar ainda mais esse benchmarking em relação a tabelas, tendo uma tabela com 131.072 linhas. Você pode então fazer uma consulta que conta de propósito lento.
Primeiro crie a tabela e preencha-a com 131.072 linhas
USE mybmark;
CREATE TABLE mytable (A int) ENGINE=MyISAM;
INSERT INTO mytable VALUES (1);
INSERT INTO mytable SELECT A FROM mytable;
INSERT INTO mytable SELECT A FROM mytable;
INSERT INTO mytable SELECT A FROM mytable;
INSERT INTO mytable SELECT A FROM mytable;
INSERT INTO mytable SELECT A FROM mytable;
INSERT INTO mytable SELECT A FROM mytable;
INSERT INTO mytable SELECT A FROM mytable;
INSERT INTO mytable SELECT A FROM mytable;
INSERT INTO mytable SELECT A FROM mytable;
INSERT INTO mytable SELECT A FROM mytable;
INSERT INTO mytable SELECT A FROM mytable;
INSERT INTO mytable SELECT A FROM mytable;
INSERT INTO mytable SELECT A FROM mytable;
INSERT INTO mytable SELECT A FROM mytable;
INSERT INTO mytable SELECT A FROM mytable;
INSERT INTO mytable SELECT A FROM mytable;
INSERT INTO mytable SELECT A FROM mytable;
INSERT INTO mytable SELECT A FROM mytable;
Em seguida, adicione a contagem lenta de mytable
em mybmark
. testproc
DELIMITER $$
DROP PROCEDURE IF EXISTS 'mybmark'.'testproc' $$
CREATE PROCEDURE 'mybmark'.'testproc' ()
BEGIN
DECLARE answer INT;
SELECT COUNT(1) INTO answer FROM mybmark.mytable WHERE 1=1;
END $$
DELIMITER ;
Agora, chame mybmark
. mybenchmark
10 vezes
call mybmark.mybenchmark(100,'CALL mybmark.testproc()');
call mybmark.mybenchmark(1000,'CALL mybmark.testproc()');
call mybmark.mybenchmark(10000,'CALL mybmark.testproc()');
call mybmark.mybenchmark(100000,'CALL mybmark.testproc()');
Execute todas essas etapas no MySQL Local Machine e no Amazon RDS
Eu escrevi este algoritmo em 3 de abril de 2012: link