From 4df73ced0dba74afa7d46a7e38109f85a9e45a24 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Sat, 8 Nov 2014 12:54:02 -0800 Subject: [PATCH] Add benchmark for Jekyll.sanitized_path --- benchmark/jekyll-sanitize-path | 46 ++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 benchmark/jekyll-sanitize-path diff --git a/benchmark/jekyll-sanitize-path b/benchmark/jekyll-sanitize-path new file mode 100644 index 00000000..231de275 --- /dev/null +++ b/benchmark/jekyll-sanitize-path @@ -0,0 +1,46 @@ +#!/usr/bin/env ruby + +require_relative '../lib/jekyll' +require 'benchmark/ips' + +base_directory = Dir.pwd + +Benchmark.ips do |x| + # + # Does not include the base_directory + # + x.report('with no questionable path') do + Jekyll.sanitized_path(base_directory, '') + end + x.report('with a single-part questionable path') do + Jekyll.sanitized_path(base_directory, 'thingy') + end + x.report('with a multi-part questionable path') do + Jekyll.sanitized_path(base_directory, 'thingy/in/my/soup') + end + x.report('with a single-part traversal path') do + Jekyll.sanitized_path(base_directory, '../thingy') + end + x.report('with a multi-part traversal path') do + Jekyll.sanitized_path(base_directory, '../thingy/in/my/../../soup') + end + + # + # Including the base_directory + # + x.report('with the exact same paths') do + Jekyll.sanitized_path(base_directory, base_directory) + end + x.report('with a single-part absolute path including the base_directory') do + Jekyll.sanitized_path(base_directory, File.join(base_directory, 'thingy')) + end + x.report('with a multi-part absolute path including the base_directory') do + Jekyll.sanitized_path(base_directory, File.join(base_directory, 'thingy/in/my/soup')) + end + x.report('with a single-part traversal path including the base_directory') do + Jekyll.sanitized_path(base_directory, File.join(base_directory, 'thingy/..')) + end + x.report('with a multi-part traversal path including the base_directory') do + Jekyll.sanitized_path(base_directory, File.join('thingy/in/my/../../soup')) + end +end