diff --git a/README.md b/README.md index b817da5..dc5ed34 100644 --- a/README.md +++ b/README.md @@ -75,6 +75,38 @@ doc.where_class("summary") { |tag| puts tag.node } # =>
..
``` +## Benchmark + +I know you love benchmark between **Ruby** & **Crystal** so there one: + +```ruby +require "nokogiri" +t1 = Time.now +doc = Nokogiri::HTML File.read("spec/fixture/HTML.html") +1..100000.times do + doc.at_css("h1") + doc.css(".step-title"){ |tag| tag } +end +puts "executed in #{Time.now - t1} milliseconds" +``` + +> executed in 13.891784021 seconds + +```crsytal +require "crystagiri" +t = Time.now +doc = Crystagiri::HTML.from_file "./spec/fixture/HTML.html" +1..100000.times do + doc.at_css("h1") + doc.css(".step-title") { |tag| tag } +end +puts "executed in #{Time.now - t} milliseconds" +``` + +> executed in 00:00:06.6636804 seconds + +Crystagiri is more than **twice fatser** than Nokogiri!! + ## Development diff --git a/benchmark.cr b/benchmark.cr new file mode 100644 index 0000000..5e8a7c5 --- /dev/null +++ b/benchmark.cr @@ -0,0 +1,8 @@ +require "./src/crystagiri" +t = Time.now +doc = Crystagiri::HTML.from_file "./spec/fixture/HTML.html" +1..100000.times do + doc.at_css("h1") + doc.css(".step-title") { |tag| tag } +end +puts "executed in #{Time.now - t} seconds" diff --git a/benchmark.rb b/benchmark.rb new file mode 100644 index 0000000..413fa9c --- /dev/null +++ b/benchmark.rb @@ -0,0 +1,8 @@ +require "nokogiri" +t1 = Time.now +doc = Nokogiri::HTML File.read("spec/fixture/HTML.html") +1..100000.times do + doc.at_css("h1") + doc.css(".step-title"){|tag| tag} +end +puts "executed in #{Time.now - t1} seconds" \ No newline at end of file diff --git a/src/crystagiri/html.cr b/src/crystagiri/html.cr index fd33cc2..f18ba13 100644 --- a/src/crystagiri/html.cr +++ b/src/crystagiri/html.cr @@ -1,4 +1,5 @@ require "http/client" +require "xml" module Crystagiri # Represent an Html document who can be parsed