From 05229cef45fe04ed2bd0effd35eef271f7599879 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Fri, 31 Jan 2020 16:53:04 +0900 Subject: Improve `String#slice!` performance Instead of searching twice to extract and to delete, extract and delete the found position at the first search. This makes faster nearly twice, for regexps and strings. | |compare-ruby|built-ruby| |:-------------|-----------:|---------:| |regexp-short | 2.143M| 3.918M| |regexp-long | 105.162k| 205.410k| |string-short | 3.789M| 7.964M| |string-long | 1.301M| 2.457M| --- benchmark/string_slice.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 benchmark/string_slice.yml (limited to 'benchmark') diff --git a/benchmark/string_slice.yml b/benchmark/string_slice.yml new file mode 100644 index 0000000000..fc2393c5d1 --- /dev/null +++ b/benchmark/string_slice.yml @@ -0,0 +1,11 @@ +prelude: | + long_string = "x"*1000+"-hår" +benchmark: + regexp-short: | + "x-hår".slice!(/-(.)(.)(.)/, 3) + regexp-long: | + long_string.dup.slice!(/-(.)(.)(.)/, 3) + string-short: | + "x-hår".slice!("r") + string-long: | + long_string.dup.slice!("r") -- cgit v1.2.3