Last active
September 23, 2022 16:46
-
-
Save erichosick/347a5d021c64f2ec6b8050eb7adab027 to your computer and use it in GitHub Desktop.
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; | |
DECLARE d_up_sql text; | |
DECLARE d_down_sql text; | |
BEGIN | |
d_up_sql = ' | |
CREATE TABLE IF NOT EXISTS public.gen_random_uuid ( | |
id uuid PRIMARY KEY DEFAULT gen_random_uuid(), | |
info bigint | |
); | |
CREATE TABLE IF NOT EXISTS public.bigint_identity ( | |
id bigint PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, | |
info bigint | |
); | |
'; | |
d_down_sql = ' | |
DROP TABLE IF EXISTS public.gen_random_uuid; | |
DROP TABLE IF EXISTS public.bigint_identity; | |
'; | |
d_left_sql = ' | |
INSERT INTO public.gen_random_uuid(info) | |
SELECT 1 | |
FROM generate_series(%s,%s) AS series; | |
'; | |
d_right_sql = ' | |
INSERT INTO public.bigint_identity(info) | |
SELECT 1 | |
FROM generate_series(%s,%s) AS series; | |
'; | |
FOR run_number IN 1..4 LOOP | |
CALL benchmark.execute( | |
FORMAT('gen_random_uuid idx uniq 10^%s', run_number), | |
'identity idx uniq'::text, | |
(10^run_number)::bigint, | |
FORMAT(d_left_sql, 1, 10^run_number), | |
FORMAT(d_right_sql, 1, 10^run_number), | |
d_exec_count, d_up_sql, d_down_sql | |
); | |
END LOOP; | |
FOR run_number IN 1..9 LOOP | |
CALL benchmark.execute( | |
FORMAT('gen_random_uuid idx uniq %s*10^5',run_number), | |
'identity idx uniq'::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, d_up_sql, d_down_sql | |
); | |
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