forked from dlee0113/oracle_pl_sql_programming
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathassoc_array_perf.tst
112 lines (89 loc) · 2.88 KB
/
assoc_array_perf.tst
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
SET SERVEROUTPUT ON FORMAT WRAPPED
CREATE OR REPLACE PROCEDURE assoc_array_index_test (
iterations_in IN PLS_INTEGER DEFAULT 10000
, length_in IN PLS_INTEGER DEFAULT 100
)
IS
TYPE tab_bynum_tabtype IS TABLE OF employees%ROWTYPE
INDEX BY PLS_INTEGER;
TYPE tab_byvc_tabtype IS TABLE OF employees%ROWTYPE
INDEX BY VARCHAR2 (32767);
bynum_tab tab_bynum_tabtype;
byvc_tab tab_byvc_tabtype;
v_salary NUMBER;
BEGIN
DBMS_OUTPUT.put_line
( 'Compare String and Integer Indexing, Iterations = '
|| iterations_in
|| ' Length = '
|| length_in
);
FOR rec IN (SELECT *
FROM employees)
LOOP
bynum_tab (rec.employee_id) := rec;
END LOOP;
FOR rec IN (SELECT *
FROM employees)
LOOP
byvc_tab (RPAD (rec.last_name, length_in, 'x')) := rec;
END LOOP;
sf_timer.start_timer;
FOR indx IN 1 .. iterations_in
LOOP
FOR rec IN (SELECT *
FROM employees)
LOOP
v_salary := bynum_tab (rec.employee_id).salary;
END LOOP;
END LOOP;
sf_timer.show_elapsed_time ('Index by PLS_INTEGER '
|| length_in
);
sf_timer.start_timer;
FOR indx IN 1 .. iterations_in
LOOP
FOR rec IN (SELECT *
FROM employees)
LOOP
v_salary := byvc_tab (RPAD (rec.last_name, length_in, 'x')).salary;
END LOOP;
END LOOP;
sf_timer.show_elapsed_time ('Index by VARCHAR2 ' || length_in);
END assoc_array_index_test;
/
BEGIN
assoc_array_index_test (10000, 100);
assoc_array_index_test (10000, 1000);
assoc_array_index_test (10000, 10000);
/*
Compare String and Integer Indexing, Iterations = 10000 Length = 100
Timings in seconds for "By Num":
Elapsed = 4.72 - per rep .000472
CPU = 4.49 - per rep .000449
Timings in seconds for "By VC":
Elapsed = 5.43 - per rep .000543
CPU = 5.44 - per rep .000544
Compare String and Integer Indexing, Iterations = 10000 Length = 1000
Timings in seconds for "By Num":
Elapsed = 4.64 - per rep .000464
CPU = 4.53 - per rep .000453
Timings in seconds for "By VC":
Elapsed = 7.78 - per rep .000778
CPU = 7.76 - per rep .000776
Compare String and Integer Indexing, Iterations = 10000 Length = 10000
Timings in seconds for "By Num":
Elapsed = 5.09 - per rep .000509
CPU = 4.56 - per rep .000456
Timings in seconds for "By VC":
Elapsed = 31.72 - per rep .003172
CPU = 31.66 - per rep .003166
*/
END;
/
/*======================================================================
| Supplement to the fifth edition of Oracle PL/SQL Programming by Steven
| Feuerstein with Bill Pribyl, Copyright (c) 1997-2009 O'Reilly Media, Inc.
| To submit corrections or find more code samples visit
| http://oreilly.com/catalog/9780596514464/
*/