Skip to content

Commit

Permalink
add benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
madeindjs committed Dec 8, 2016
1 parent 5a6481f commit f42a3af
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 0 deletions.
32 changes: 32 additions & 0 deletions README.md
Expand Up @@ -75,6 +75,38 @@ doc.where_class("summary") { |tag| puts tag.node }
# => <div class="summary"> .. </div>
```

## 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

Expand Down
8 changes: 8 additions & 0 deletions 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"
8 changes: 8 additions & 0 deletions 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"
1 change: 1 addition & 0 deletions src/crystagiri/html.cr
@@ -1,4 +1,5 @@
require "http/client"
require "xml"

module Crystagiri
# Represent an Html document who can be parsed
Expand Down

0 comments on commit f42a3af

Please sign in to comment.