Last active
September 23, 2022 16:45
-
-
Save erichosick/d7801a573b2a8919e2aa704c7459251f to your computer and use it in GitHub Desktop.
Benchmark of gen_random_uuid versus uuid_generate_v1
This file contains hidden or 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
-- You must run the benchmark schema localed in | |
-- https://gist.github.com/erichosick/eeadc41e33ea2a91bd136b9433e73dc7 | |
-- before running the following benchmark | |
DO $$ | |
DECLARE d_exec_count int = 20; | |
DECLARE d_left_sql text; | |
DECLARE d_right_sql text; | |
BEGIN | |
d_left_sql = ' | |
SELECT uuid_generate_v1() | |
FROM generate_series(%s,%s) AS series; | |
'; | |
d_right_sql = ' | |
SELECT CLOCK_TIMESTAMP(), gen_random_uuid() | |
FROM generate_series(%s,%s) AS series; | |
'; | |
FOR run_number IN 1..4 LOOP | |
CALL benchmark.execute( | |
FORMAT('uuid_generate_v1 10^%s', run_number), | |
'clock_timestamp + gen_random_uuid'::text, | |
(10^run_number)::bigint, | |
FORMAT(d_left_sql, 1, 10^run_number), | |
FORMAT(d_right_sql, 1, 10^run_number), | |
d_exec_count | |
); | |
END LOOP; | |
FOR run_number IN 1..9 LOOP | |
CALL benchmark.execute( | |
FORMAT('uuid_generate_v1 %s*10^5',run_number), | |
'clock_timestamp + gen_random_uuid'::text, | |
(run_number*10^5)::bigint, | |
FORMAT(d_left_sql, 1, run_number*10^5), | |
FORMAT(d_right_sql, 1, run_number*10^5), | |
d_exec_count | |
); | |
END LOOP; | |
END; | |
$$; | |
SELECT | |
thresh.faster_sql, | |
thresh.description_sql_left || ' - ' | |
|| thresh.description_sql_right || ' | ' | |
|| thresh.times_faster || 'x | ' | |
|| thresh.average_left || ' ± ' || | |
thresh.standard_deviation_left || ' | ' || | |
thresh.average_right || ' ± ' || | |
standard_deviation_right AS data_row | |
FROM benchmark.compare_result_outcome AS thresh | |
INNER JOIN benchmark.compare AS comp | |
ON comp.description_sql_left = thresh.description_sql_left | |
AND comp.description_sql_right = thresh.description_sql_right | |
ORDER BY comp.created_on ASC; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment