Sha256: 3c9f964217bb64c23da65f2db197be58612fdc4a9cae604988cc341699eb271b

Contents?: true

Size: 938 Bytes

Versions: 8

Compression:

Stored size: 938 Bytes

Contents

# frozen_string_literal: true

require 'benchmark/ips'
require 'trenni/markup'

RSpec.describe Trenni::Markup do
	let(:code_string) {'javascript:if (foo < bar) {alert("Hello World")}'}
	let(:general_string) {"a" * code_string.size}
	
	it "should be fast to parse large documents" do
		Benchmark.ips do |x|
			x.report("CGI.escapeHTML(general_string)") do |times|
				while (times -= 1) >= 0
					CGI.escapeHTML(general_string)
				end
			end
			
			x.report("CGI.escapeHTML(code_string)") do |times|
				while (times -= 1) >= 0
					CGI.escapeHTML(code_string)
				end
			end
			
			x.report("Trenni::Markup.escape_string(general_string)") do |times|
				while (times -= 1) >= 0
					Trenni::Markup.escape_string(general_string)
				end
			end
			
			x.report("Trenni::Markup.escape_string(code_string)") do |times|
				while (times -= 1) >= 0
					Trenni::Markup.escape_string(code_string)
				end
			end
			
			x.compare!
		end
	end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
trenni-3.14.0 spec/trenni/markup_performance_spec.rb
trenni-3.13.2 spec/trenni/markup_performance_spec.rb
trenni-3.13.1 spec/trenni/markup_performance_spec.rb
trenni-3.13.0 spec/trenni/markup_performance_spec.rb
trenni-3.12.0 spec/trenni/markup_performance_spec.rb
trenni-3.11.0 spec/trenni/markup_performance_spec.rb
trenni-3.10.0 spec/trenni/markup_performance_spec.rb
trenni-3.9.0 spec/trenni/markup_performance_spec.rb