Last active
July 6, 2017 10:31
-
-
Save ajoydas/8ea82d28a5594e0ed1b853cf70985b7f to your computer and use it in GitHub Desktop.
This Oracle procedure counts the time required to run a single, total & avg. query time.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
In {FOR i in 1..30} set how many time you want to iterate & set same value to | |
{dbms_output.put_line('Avg Time: '||(totaltime/30));} in the last line to find the avg. | |
Here I have set 30 times to iterate. | |
You have to call it like- | |
DECLARE | |
BEGIN | |
dbms_output.put_line('Query 1'); | |
performance('Select u.accountId , count(b.badgesId) as cnt From Users u, Badges b where u.userId = b.userId and u.communityId = 1 and b.badgesdate between ''01-jan-2015'' and ''01-jun-2017'' group by u.accountId order by cnt DESC'); | |
dbms_output.put_line('Query 2'); | |
performance('select t.tagname,count(c.commentid) cnt FROM Tags t, PostTages pt, Posts p, comments c WHERE t.tagid=pt.tagid and pt.postid=p.postid and p.postid= c.postid GROUP BY t.tagname order by cnt DESC'); | |
END; | |
//The Procedure | |
CREATE OR REPLACE | |
PROCEDURE performance(p_sql IN VARCHAR2) AS | |
l_cursor INTEGER; | |
l_dummy NUMBER; | |
timestart NUMBER; | |
timeend NUMBER; | |
totaltime NUMBER; | |
BEGIN | |
totaltime:=0; | |
FOR i in 1..30 | |
LOOP | |
timestart := dbms_utility.get_time(); | |
l_cursor := dbms_sql.open_cursor; | |
dbms_sql.parse(l_cursor, p_sql, dbms_sql.native); | |
l_dummy := dbms_sql.execute(l_cursor); | |
LOOP | |
EXIT WHEN dbms_sql.fetch_rows(l_cursor) <= 0; | |
END LOOP; | |
dbms_sql.close_cursor(l_cursor); | |
timeend := dbms_utility.get_time(); | |
dbms_output.put_line((timeend - timestart)/100); | |
totaltime:= totaltime + (timeend - timestart)/100; | |
END LOOP; | |
dbms_output.put_line('Total Time: '||totaltime); | |
dbms_output.put_line('Avg Time: '||(totaltime/30)); | |
END; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment