Sha256: 2fd8a47dcadb3e0688df77a048ed459298dda206a9b53dc3c7145ff3b16532e3

Contents?: true

Size: 1.74 KB

Versions: 12

Compression:

Stored size: 1.74 KB

Contents

require 'benchmark/ips'
require 'trenni/parsers'
require 'trenni/entities'

require 'nokogiri'

RSpec.describe Trenni::Parsers do
	# include_context "profile"
	
	describe '#parse_markup' do
		let(:xhtml_path) {File.expand_path('corpus/large.xhtml', __dir__)}
		let(:xhtml_buffer) {Trenni::FileBuffer.new(xhtml_path)}
		let(:entities) {Trenni::Entities::HTML5}
		
		it "should be fast to parse large documents" do
			Benchmark.ips do |x|
				x.report("Large (Trenni)") do |times|
					delegate = Trenni::ParseDelegate.new
					
					while (times -= 1) >= 0
						Trenni::Parsers.parse_markup(xhtml_buffer, delegate, entities)
						
						delegate.events.clear
					end
				end
				
				x.report("Large (Nokogiri)") do |times|
					delegate = Trenni::ParseDelegate.new
					parser = Nokogiri::HTML::SAX::Parser.new(delegate)
					
					while (times -= 1) >= 0
						parser.parse(xhtml_buffer.read)
						
						delegate.events.clear
					end
				end
				
				x.compare!
			end
		end
	end
	
	describe '#parse_template' do
		let(:large_trenni_path) {File.expand_path('template_spec/large.trenni', __dir__)}
		let(:trenni_buffer) {Trenni::FileBuffer.new(large_trenni_path)}
		
		let(:large_erb_path) {File.expand_path('template_spec/large.erb', __dir__)}
		let(:erb_buffer) {Trenni::FileBuffer.new(large_erb_path)}
		
		it "should be fast to parse large templates" do
			Benchmark.ips do |x|
				x.report("Large (Trenni)") do |times|
					delegate = Trenni::ParseDelegate.new
					
					while (times -= 1) >= 0
						Trenni::Parsers.parse_template(trenni_buffer, delegate)
						
						delegate.events.clear
					end
				end
				
				x.report("Large (ERB)") do |times|
					while (times -= 1) >= 0
						ERB.new(erb_buffer.read)
					end
				end
				
				x.compare!
			end
		end
	end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
trenni-3.7.1 spec/trenni/parsers_performance_spec.rb
trenni-3.7.0 spec/trenni/parsers_performance_spec.rb
trenni-3.6.1 spec/trenni/parsers_performance_spec.rb
trenni-3.6.0 spec/trenni/parsers_performance_spec.rb
trenni-3.5.0 spec/trenni/parsers_performance_spec.rb
trenni-3.4.0 spec/trenni/parsers_performance_spec.rb
trenni-3.3.0 spec/trenni/parsers_performance_spec.rb
trenni-3.2.0 spec/trenni/parsers_performance_spec.rb
trenni-3.1.3 spec/trenni/parsers_performance_spec.rb
trenni-3.1.2 spec/trenni/parsers_performance_spec.rb
trenni-3.1.1 spec/trenni/parsers_performance_spec.rb
trenni-3.1.0 spec/trenni/parsers_performance_spec.rb