From 4da6bfd81ae1369eb2d1222293a266ab3c3f9369 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Wed, 25 Feb 2015 11:57:49 -0800 Subject: [PATCH] Add benchmark for end_with? vs regexp --- benchmark/end-with-vs-regexp | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 benchmark/end-with-vs-regexp diff --git a/benchmark/end-with-vs-regexp b/benchmark/end-with-vs-regexp new file mode 100644 index 00000000..cb849f42 --- /dev/null +++ b/benchmark/end-with-vs-regexp @@ -0,0 +1,13 @@ +require 'benchmark/ips' + +Benchmark.ips do |x| + path_without_ending_slash = '/some/very/very/long/path/to/a/file/i/like' + x.report('no slash regexp') { path_without_ending_slash =~ /\/$/ } + x.report('no slash end_with?') { path_without_ending_slash.end_with?("/") } +end + +Benchmark.ips do |x| + path_with_ending_slash = '/some/very/very/long/path/to/a/file/i/like/' + x.report('slash regexp') { path_with_ending_slash =~ /\/$/ } + x.report('slash end_with?') { path_with_ending_slash.end_with?("/") } +end