Init
This commit is contained in:
commit
537f2d483f
|
@ -0,0 +1,13 @@
|
|||
# Quick & Dirty Ruby Benchmarks
|
||||
|
||||
Just some fun little benchmarks I did with the help of [benchmark-ips](https://github.com/evanphx/benchmark-ips).
|
||||
|
||||
## Usage
|
||||
|
||||
Run the `.rb` files with `INSTALL_GEMS=1` in your environment to make sure you install all the dependencies.
|
||||
|
||||
### Example
|
||||
|
||||
```bash
|
||||
env INSTALL_GEMS=1 ruby markup.rb
|
||||
```
|
|
@ -0,0 +1,62 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'bundler/inline'
|
||||
|
||||
gemfile ENV.has_key?('INSTALL_GEMS') do
|
||||
source 'https://rubygems.org'
|
||||
gem 'benchmark-ips'
|
||||
gem 'tilt'
|
||||
gem 'kramdown'
|
||||
gem 'rdiscount'
|
||||
gem 'redcarpet'
|
||||
gem 'bluecloth'
|
||||
gem 'maruku'
|
||||
gem 'commonmarker'
|
||||
gem 'RedCloth'
|
||||
gem 'creole'
|
||||
gem 'rinku'
|
||||
gem 'wikicloth'
|
||||
gem 'asciidoctor'
|
||||
end
|
||||
|
||||
require 'benchmark/ips'
|
||||
|
||||
Benchmark.ips do |x|
|
||||
x.report('Kramdown:') do
|
||||
Tilt::KramdownTemplate.new('markup/markdown.md').render
|
||||
end
|
||||
|
||||
x.report('Redcarpet:') do
|
||||
Tilt::RedcarpetTemplate.new('markup/markdown.md').render
|
||||
end
|
||||
|
||||
x.report('BlueCloth:') do
|
||||
Tilt::BlueClothTemplate.new('markup/markdown.md').render
|
||||
end
|
||||
|
||||
x.report('Maruku:') do
|
||||
Tilt::MarukuTemplate.new('markup/markdown.md').render
|
||||
end
|
||||
|
||||
x.report('CommonMarker:') do
|
||||
Tilt::CommonMarkerTemplate.new('markup/markdown.md').render
|
||||
end
|
||||
|
||||
x.report('RedCloth:') do
|
||||
Tilt.new('markup/textile.textile').render
|
||||
end
|
||||
|
||||
x.report('Creole:') do
|
||||
Tilt.new('markup/creole.creole').render
|
||||
end
|
||||
|
||||
x.report('WikiText:') do
|
||||
Tilt.new('markup/wikitext.mediawiki').render
|
||||
end
|
||||
|
||||
x.report('Asciidoctor:') do
|
||||
Tilt.new('markup/asciidoc.adoc').render
|
||||
end
|
||||
|
||||
x.compare!
|
||||
end
|
|
@ -0,0 +1,5 @@
|
|||
= Hello from Markdown!
|
||||
|
||||
**This is bold** and _this is italic_. **This is _bold and italic_**.
|
||||
|
||||
Another paragraph is finally here. http://evanwalsh.net[Here's a link].
|
|
@ -0,0 +1,5 @@
|
|||
= Hello from LIBRARY!
|
||||
|
||||
**This is bold** and //this is italic//. **This is //bold and italic//**.
|
||||
|
||||
Another paragraph is finally here. [[Here's a link|http://evanwalsh.net]].
|
|
@ -0,0 +1,5 @@
|
|||
# Hello from Markdown!
|
||||
|
||||
**This is bold** and _this is italic_. **This is _bold and italic_**.
|
||||
|
||||
Another paragraph is finally here. [Here's a link](http://evanwalsh.net).
|
|
@ -0,0 +1,5 @@
|
|||
Hello from LIBRARY!
|
||||
|
||||
**This is bold** and _this is italic_. **This is _bold and italic_**.
|
||||
|
||||
Another paragraph is finally here. [Here's a link](http://evanwalsh.net).
|
|
@ -0,0 +1,5 @@
|
|||
h1. Hello from Markdown!
|
||||
|
||||
*This is bold* and _this is italic_. *This is _bold and italic_*.
|
||||
|
||||
Another paragraph is finally here. "Here's a link":http://evanwalsh.net.
|
|
@ -0,0 +1,5 @@
|
|||
= Hello from WikiText!
|
||||
|
||||
'''This is bold''' and ''this is italic'''. '''This is ''bold and italic'''''.
|
||||
|
||||
Another paragraph is finally here. [[Here's a link|http://evanwalsh.net]].
|
|
@ -0,0 +1,91 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'bundler/inline'
|
||||
|
||||
gemfile ENV.key?('INSTALL_GEMS') do
|
||||
source 'https://rubygems.org'
|
||||
gem 'benchmark-ips'
|
||||
gem 'bson'
|
||||
gem 'msgpack'
|
||||
gem 'cbor'
|
||||
end
|
||||
|
||||
require 'json'
|
||||
require 'yaml'
|
||||
require 'benchmark/ips'
|
||||
|
||||
data = {
|
||||
account_id: 1,
|
||||
type: 'artist_update',
|
||||
subject: {
|
||||
id: 1,
|
||||
type: 'Artist'
|
||||
},
|
||||
author: {
|
||||
id: 1,
|
||||
type: 'Account'
|
||||
}
|
||||
}
|
||||
|
||||
json = JSON.generate(data)
|
||||
bson = data.to_bson
|
||||
msgpack = MessagePack.pack(data)
|
||||
cbor = data.to_cbor
|
||||
yaml = YAML.dump data
|
||||
|
||||
puts "JSON (#{json.bytesize} bytes): #{json}"
|
||||
puts "MessagePack (#{msgpack.bytesize} bytes): #{msgpack}"
|
||||
puts "BSON (#{bson.to_s.bytesize} bytes): #{bson}"
|
||||
puts "CBOR (#{cbor.to_s.bytesize} byes): #{cbor}"
|
||||
puts "YAML (#{yaml.bytesize} bytes): #{yaml}"
|
||||
|
||||
puts "\nBenchmarks"
|
||||
|
||||
Benchmark.ips do |x|
|
||||
x.report('json ->') do
|
||||
JSON.generate(data)
|
||||
end
|
||||
|
||||
x.report('msgpack ->') do
|
||||
MessagePack.pack(data)
|
||||
end
|
||||
|
||||
x.report('bson ->') do
|
||||
data.to_bson
|
||||
end
|
||||
|
||||
x.report('cbor ->') do
|
||||
data.to_cbor
|
||||
end
|
||||
|
||||
x.report('yaml ->') do
|
||||
YAML.dump(data)
|
||||
end
|
||||
|
||||
x.compare!
|
||||
end
|
||||
|
||||
Benchmark.ips do |x|
|
||||
x.report('<- json') do
|
||||
JSON.parse(json)
|
||||
end
|
||||
|
||||
x.report('<- msgpack') do
|
||||
MessagePack.unpack(msgpack)
|
||||
end
|
||||
|
||||
x.report('<- bson') do
|
||||
bson.rewind!
|
||||
Hash.from_bson(bson)
|
||||
end
|
||||
|
||||
x.report('<- cbor') do
|
||||
CBOR.decode(cbor)
|
||||
end
|
||||
|
||||
x.report('<-- yaml') do
|
||||
YAML.load(yaml)
|
||||
end
|
||||
|
||||
x.compare!
|
||||
end
|
|
@ -0,0 +1,20 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>Hello from Erubi!</title>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
||||
<link rel="stylesheet" href="/test.css">
|
||||
<meta name="current_time" content="<%= Time.now.to_s %>">
|
||||
</head>
|
||||
<body>
|
||||
<div id="content">
|
||||
<div class="container">
|
||||
<% 100.times do |i| %>
|
||||
<div>This is div #<%= i %></div>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,29 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class TestView < Fortitude::Widget
|
||||
doctype :html5
|
||||
|
||||
def content
|
||||
doctype!
|
||||
|
||||
html do
|
||||
head do
|
||||
title 'Hello from Fortitude'
|
||||
meta charset: 'utf-8'
|
||||
meta name: 'viewport', content: 'width=device-width, initial-scale=1'
|
||||
link rel: 'stylesheet', href: '/test.css'
|
||||
meta name: 'current_time', content: Time.now.to_s
|
||||
end
|
||||
|
||||
body do
|
||||
div(id: 'content') do
|
||||
div(class: 'container') do
|
||||
100.times do |i|
|
||||
div("This is div ##{i}")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,16 @@
|
|||
!!!
|
||||
%html{lang: "en"}
|
||||
%head
|
||||
%meta{content: "text/html; charset=UTF-8", "http-equiv" => "Content-Type"}/
|
||||
%title Hello from Erubi!
|
||||
%meta{charset: "UTF-8"}/
|
||||
%meta{content: "width=device-width, initial-scale=1.0", name: "viewport"}/
|
||||
%meta{content: "ie=edge", "http-equiv" => "X-UA-Compatible"}/
|
||||
%link{href: "/test.css", rel: "stylesheet"}/
|
||||
%meta{content: Time.now.to_s, name: "current_time"}/
|
||||
%body
|
||||
#content
|
||||
.container
|
||||
- 100.times do |i|
|
||||
%div
|
||||
This is div ##{i}
|
|
@ -0,0 +1,23 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<title>Hello from Liquid!</title>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
||||
<link rel="stylesheet" href="/test.css">
|
||||
<meta name="current_time" content="{{time}}">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="content">
|
||||
<div class="container">
|
||||
{{#each number}}
|
||||
<div>This is div #{{@index}}</div>
|
||||
{{/each}}
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
|
@ -0,0 +1,20 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>Hello from Liquid!</title>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
||||
<link rel="stylesheet" href="/test.css">
|
||||
<meta name="current_time" content="{{ "now" | date: "%Y-%m-%d %H:%M" }}">
|
||||
</head>
|
||||
<body>
|
||||
<div id="content">
|
||||
<div class="container">
|
||||
{% for i in (0..100) %}
|
||||
<div>This is div #{{ i }}</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,19 @@
|
|||
html do
|
||||
head do
|
||||
title 'Hello from Markaby'
|
||||
meta charset: 'utf-8'
|
||||
meta name: 'viewport', content: 'width=device-width, initial-scale=1'
|
||||
link rel: 'stylesheet', href: '/test.css'
|
||||
meta name: 'current_time', content: Time.now.to_s
|
||||
end
|
||||
|
||||
body do
|
||||
div(id: 'content') do
|
||||
div(class: 'container') do
|
||||
100.times do |i|
|
||||
div("This is div ##{i}")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,13 @@
|
|||
doctype html
|
||||
html
|
||||
head
|
||||
title Hello from Slim!
|
||||
meta charset="utf-8"
|
||||
meta name="viewport" content="width=device-width, initial-scale=1"
|
||||
link rel="stylesheet" href="/test.css"
|
||||
meta name="current_time" content=Time.now.to_s
|
||||
body
|
||||
#content
|
||||
.container
|
||||
- 100.times do |i|
|
||||
div This is div ##{i}
|
|
@ -0,0 +1,7 @@
|
|||
user system total real
|
||||
Slim: 3.180568 0.027484 3.208052 ( 3.209399)
|
||||
Markaby: 1.742859 0.023275 1.766134 ( 1.773957)
|
||||
Erubi: 0.337117 0.022639 0.359756 ( 0.367103)
|
||||
HAML: 4.148871 0.031099 4.179970 ( 4.188886)
|
||||
|
||||
---
|
|
@ -0,0 +1,84 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'bundler/inline'
|
||||
|
||||
gemfile ENV.has_key?('INSTALL_GEMS') do
|
||||
source 'https://rubygems.org'
|
||||
gem 'benchmark-ips'
|
||||
gem 'erubi'
|
||||
gem 'fortitude'
|
||||
gem 'haml'
|
||||
gem 'markaby'
|
||||
gem 'slim'
|
||||
gem 'tilt'
|
||||
gem 'arbre'
|
||||
gem 'liquid'
|
||||
gem 'tilt-handlebars'
|
||||
end
|
||||
|
||||
require 'benchmark/ips'
|
||||
|
||||
Benchmark.ips do |x|
|
||||
x.report('Slim:') do
|
||||
Tilt.new('templates/slim.slim').render
|
||||
end
|
||||
|
||||
# x.report('Fortitude:') do
|
||||
# Tilt.new('templates/fortitude.rb').render
|
||||
# end
|
||||
|
||||
# x.report('Arbre:') do
|
||||
# view = Arbre::Context.new do
|
||||
# html do
|
||||
# head do
|
||||
# title 'Hello from Arbre'
|
||||
# meta charset: 'utf-8'
|
||||
# meta name: 'viewport', content: 'width=device-width, initial-scale=1'
|
||||
# link rel: 'stylesheet', href: '/test.css'
|
||||
# meta name: 'current_time', content: Time.now.to_s
|
||||
# end
|
||||
|
||||
# body do
|
||||
# div(id: 'content') do
|
||||
# div(class: 'container') do
|
||||
# 100.times do |i|
|
||||
# div("This is div ##{i}")
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
|
||||
# view.to_s
|
||||
# end
|
||||
|
||||
x.report('Markaby:') do
|
||||
Tilt.new('templates/markaby.mab').render
|
||||
end
|
||||
|
||||
x.report('Erubi:') do
|
||||
Tilt.new('templates/erubi.erb').render
|
||||
end
|
||||
|
||||
x.report('ERB:') do
|
||||
Tilt::ERBTemplate.new('templates/erubi.erb').render
|
||||
end
|
||||
|
||||
x.report('HAML:') do
|
||||
Tilt.new('templates/haml.haml').render
|
||||
end
|
||||
|
||||
x.report('Liquid:') do
|
||||
Tilt.new('templates/liquid.liquid').render
|
||||
end
|
||||
|
||||
x.report('Handlebars:') do
|
||||
Tilt.new('templates/handlebars.hbs', {
|
||||
time: Time.now.to_s,
|
||||
numbers: (0..100).to_a
|
||||
})
|
||||
end
|
||||
|
||||
x.compare!
|
||||
end
|
Loading…
Reference in New Issue