-
Notifications
You must be signed in to change notification settings - Fork 849
/
Copy pathelapsed-time-calculator.sql
58 lines (47 loc) · 1.19 KB
/
elapsed-time-calculator.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
This simple package uses DBMS_UTILITY.GET_CPU_TIME to calculate the elapsed time,
down to the hundredth of a second, of code execution. Very useful for comparing
performance of different implementations.
*/
CREATE OR REPLACE PACKAGE tmr
IS
PROCEDURE start_timer;
PROCEDURE show_elapsed_time (message_in IN VARCHAR2 := NULL);
END;
/
CREATE OR REPLACE PACKAGE BODY tmr
IS
last_timing NUMBER;
PROCEDURE start_timer
IS
BEGIN
last_timing := DBMS_UTILITY.GET_CPU_TIME;
END;
PROCEDURE show_elapsed_time (message_in IN VARCHAR2 := NULL)
IS
BEGIN
DBMS_OUTPUT.put_line (
CASE
WHEN message_in IS NULL THEN 'Completed in:'
ELSE '"' || message_in || '" completed in: '
END
|| TO_CHAR (ROUND ((DBMS_UTILITY.GET_CPU_TIME - last_timing) / 100, 2))
|| ' seconds');
/* Reset timer */
start_timer;
END;
END;
/
DECLARE
n NUMBER;
BEGIN
tmr.start_timer;
FOR i IN 1 .. 50000
LOOP
SELECT 1 INTO n
FROM dual;
END LOOP;
DBMS_OUTPUT.PUT_LINE (n);
tmr.show_elapsed_time ('5K queries');
END;
/