Created
November 4, 2015 20:34
-
-
Save Mikulas/f9005a928c09c98856a3 to your computer and use it in GitHub Desktop.
PostgresSQL replace vs regexp_replace benchmark
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
CREATE OR REPLACE FUNCTION benchmark() RETURNS INTEGER AS | |
$BODY$ | |
BEGIN | |
FOR i IN 1..10000000 LOOP | |
PERFORM replace(replace('Lorem %ipsum_dolor sit amet, %consectetu%r_adipisici%ng elit,_sed do eiusmod', '%', '\%'), '_', '\_'); | |
END LOOP; | |
return 1; | |
END | |
$BODY$ | |
LANGUAGE 'plpgsql' ; | |
SELECT benchmark() as replace; | |
CREATE OR REPLACE FUNCTION benchmark() RETURNS INTEGER AS | |
$BODY$ | |
BEGIN | |
FOR i IN 1..10000000 LOOP | |
PERFORM regexp_replace('Lorem %ipsum_dolor sit amet, %consectetu%r_adipisici%ng elit,_sed do eiusmod', '(%|_)', '\\\1', 'g'); | |
END LOOP; | |
return 1; | |
END | |
$BODY$ | |
LANGUAGE 'plpgsql' ; | |
SELECT benchmark() as regexp_replace1; |
Author
Mikulas
commented
Nov 4, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment