CREATE OR REPLACE FUNCTION sql(int2) RETURNS int2 LANGUAGE SQL VOLATILE AS
$$
SELECT $1;
$$;

CREATE OR REPLACE FUNCTION noparams() RETURNS VOID LANGUAGE plpython3u VOLATILE AS
$$
@pytypes
def main():
	return None
$$;

CREATE OR REPLACE FUNCTION oneint2(int2) RETURNS int2 LANGUAGE plpython3u VOLATILE AS
$$
@pytypes
def main(x):
	return x
$$;

CREATE OR REPLACE FUNCTION oneint4(int4) RETURNS int4 LANGUAGE plpython3u VOLATILE AS
$$
@pytypes
def main(x):
	return x
$$;

CREATE OR REPLACE FUNCTION oneint8(int8) RETURNS int8 LANGUAGE plpython3u VOLATILE AS
$$
@pytypes
def main(x):
	return x
$$;

CREATE OR REPLACE FUNCTION onetext(text) RETURNS text LANGUAGE plpython3u VOLATILE AS
$$
@pytypes
def main(x):
	return x
$$;

CREATE OR REPLACE FUNCTION onetextarray(text[]) RETURNS text[] LANGUAGE plpython3u VOLATILE AS
$$
@pytypes
def main(x):
	return x
$$;

DROP TYPE IF EXISTS testcomp CASCADE;
CREATE TYPE testcomp AS (n1 text, n2 text, n3 text, n4 text, n5 text);
CREATE OR REPLACE FUNCTION onecomposite(testcomp) RETURNS testcomp LANGUAGE plpython3u VOLATILE AS
$$
@pytypes
def main(x):
	return x
$$;

-- initialize the language
SELECT noparams();

BEGIN;
\timing
SELECT COUNT(1) AS base FROM generate_series(1, 100000) AS g(i);
SELECT COUNT(sql(123::int2)) AS basesql FROM generate_series(1, 100000) AS g(i);
SELECT COUNT(noparams() IS NULL) AS noparams FROM generate_series(1, 100000) AS g(i);
SELECT COUNT(oneint2(123::int2)) AS oneint2 FROM generate_series(1, 100000) AS g(i);
SELECT COUNT(oneint4(123::int4)) AS oneint4 FROM generate_series(1, 100000) AS g(i);
SELECT COUNT(oneint8(123::int8)) AS oneint8 FROM generate_series(1, 100000) AS g(i);
SELECT COUNT(oneint8((2::bigint ^ 50)::int8)) AS oneint8_large FROM generate_series(1, 100000) AS g(i);
SELECT COUNT(onetext('foo'::text)) AS text FROM generate_series(1, 100000) AS g(i);
SELECT COUNT(onetext(repeat('foo', 2000))) AS text_large FROM generate_series(1, 100000) AS g(i);
SELECT COUNT(onetextarray(ARRAY['foo'::text,'bar','feh','fluffy','bunnies'])) AS textarray FROM generate_series(1, 100000) AS g(i);
SELECT COUNT(onecomposite(ROW('n1','n2','n3','n4','n5')::testcomp)) AS composite FROM generate_series(1, 100000) AS g(i);
ABORT;
