diff --git a/Gemfile b/Gemfile index bc0c0a1..42a89a9 100644 --- a/Gemfile +++ b/Gemfile @@ -8,3 +8,4 @@ gem 'haml' gem 'slim' gem 'liquid' gem 'mustache' +gem 'markaby' diff --git a/Gemfile.lock b/Gemfile.lock index 4a4d64a..14f21fa 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,6 +1,7 @@ GEM remote: https://rubygems.org/ specs: + builder (3.2.2) erubis (2.7.0) faker (1.2.0) i18n (~> 0.5) @@ -8,6 +9,8 @@ GEM tilt i18n (0.6.9) liquid (2.6.0) + markaby (0.7.2) + builder (>= 2.0.0) mustache (0.99.5) slim (2.0.2) temple (~> 0.6.6) @@ -23,6 +26,7 @@ DEPENDENCIES faker haml liquid + markaby mustache slim tilt diff --git a/README.md b/README.md index 6468ee3..98ffffd 100644 --- a/README.md +++ b/README.md @@ -2,13 +2,17 @@ #### Ruby implementations. ## Competitors +- Builder - ERB - Erubis - Haml - Liquid +- Markaby - Mustache - Slim + ... and our special guest ... + - String interpolation ## Running @@ -33,47 +37,55 @@ bundle install ## Compilation (small) (1000 runs) ## ############################################################ user system total real -string 0.040000 0.020000 0.060000 ( 0.053855) -erubis 0.060000 0.010000 0.070000 ( 0.075751) -erb 0.240000 0.030000 0.270000 ( 0.262077) -haml 0.840000 0.020000 0.860000 ( 0.865688) -slim 1.930000 0.040000 1.970000 ( 1.968993) -mustache 0.020000 0.010000 0.030000 ( 0.030289) -liquid 0.080000 0.020000 0.100000 ( 0.104174) +string 0.030000 0.020000 0.050000 ( 0.046353) +erubis 0.060000 0.020000 0.080000 ( 0.079977) +erb 0.260000 0.020000 0.280000 ( 0.273492) +haml 0.850000 0.020000 0.870000 ( 0.874163) +slim 1.970000 0.040000 2.010000 ( 2.003406) +mustache 0.020000 0.010000 0.030000 ( 0.034893) +liquid 0.050000 0.020000 0.070000 ( 0.074104) +markaby 0.030000 0.020000 0.050000 ( 0.039915) +builder 0.020000 0.010000 0.030000 ( 0.039993) ############################################################ ## Render (small) (1000 runs) ## ############################################################ user system total real -string 0.010000 0.000000 0.010000 ( 0.007824) -erubis 0.010000 0.000000 0.010000 ( 0.008019) -erb 0.010000 0.000000 0.010000 ( 0.010448) -haml 0.020000 0.000000 0.020000 ( 0.019507) -slim 0.020000 0.000000 0.020000 ( 0.019644) -mustache 0.230000 0.000000 0.230000 ( 0.232938) -liquid 0.040000 0.000000 0.040000 ( 0.044189) +string 0.010000 0.000000 0.010000 ( 0.009001) +erubis 0.010000 0.000000 0.010000 ( 0.008587) +erb 0.010000 0.000000 0.010000 ( 0.012027) +haml 0.020000 0.010000 0.030000 ( 0.022236) +slim 0.020000 0.000000 0.020000 ( 0.021628) +mustache 0.250000 0.000000 0.250000 ( 0.257850) +liquid 0.050000 0.000000 0.050000 ( 0.045442) +markaby 0.230000 0.000000 0.230000 ( 0.232095) +builder 0.200000 0.000000 0.200000 ( 0.196965) ############################################################ ## Compilation (big) (1000 runs) ## ############################################################ user system total real -string 0.030000 0.020000 0.050000 ( 0.044706) -erubis 0.140000 0.020000 0.160000 ( 0.161244) -erb 0.320000 0.030000 0.350000 ( 0.341144) -haml 1.180000 0.020000 1.200000 ( 1.205595) -slim 2.410000 0.040000 2.450000 ( 2.449355) -mustache 0.020000 0.010000 0.030000 ( 0.028152) -liquid 0.110000 0.020000 0.130000 ( 0.133382) +string 0.030000 0.020000 0.050000 ( 0.043935) +erubis 0.150000 0.020000 0.170000 ( 0.176325) +erb 0.310000 0.020000 0.330000 ( 0.325486) +haml 1.190000 0.030000 1.220000 ( 1.217889) +slim 2.430000 0.030000 2.460000 ( 2.468188) +mustache 0.020000 0.020000 0.040000 ( 0.031460) +liquid 0.110000 0.020000 0.130000 ( 0.134760) +markaby 0.030000 0.010000 0.040000 ( 0.039455) +builder 0.020000 0.020000 0.040000 ( 0.040826) ############################################################ ## Render (big) (100 runs) ## ############################################################ user system total real -string 0.390000 0.020000 0.410000 ( 0.408272) -erubis 0.440000 0.020000 0.460000 ( 0.457214) -erb 0.640000 0.020000 0.660000 ( 0.656181) -haml 0.940000 0.020000 0.960000 ( 0.965373) -slim 1.390000 0.000000 1.390000 ( 1.395409) -mustache 3.770000 0.010000 3.780000 ( 3.778392) -liquid 10.460000 0.050000 10.510000 ( 10.507224) +string 0.370000 0.020000 0.390000 ( 0.392442) +erubis 0.450000 0.020000 0.470000 ( 0.463274) +erb 0.630000 0.020000 0.650000 ( 0.651563) +haml 0.970000 0.010000 0.980000 ( 0.982174) +slim 1.410000 0.010000 1.420000 ( 1.422800) +mustache 3.760000 0.000000 3.760000 ( 3.757236) +liquid 10.440000 0.040000 10.480000 ( 10.480874) +markaby 11.560000 0.020000 11.580000 ( 11.576669) +builder 18.300000 0.030000 18.330000 ( 18.326396) ``` diff --git a/benchmark.rb b/benchmark.rb index c6477f7..8711359 100755 --- a/benchmark.rb +++ b/benchmark.rb @@ -31,7 +31,7 @@ unless File.exist?(big_data_file) raise 'Big data file not found. Please generate it with "./fakedata.rb 10000 > data/big.yml"' end -small_data = {title: 'Greetings!', username: '%username%'} +small_data = {window_title: 'Greetings!', username: '%username%'} big_data = YAML.load_file(big_data_file) def banner title @@ -97,6 +97,14 @@ ENGINES = { class: Tilt::LiquidTemplate, extension: 'liquid' }, + markaby: { + class: Tilt::MarkabyTemplate, + extension: 'mab' + }, + builder: { + class: Tilt::BuilderTemplate, + extension: 'builder' + }, } banner 'Compilation (small) (%d runs)' % COMPILE_LOOPS diff --git a/templates/builder/big.builder b/templates/builder/big.builder new file mode 100644 index 0000000..c6d909a --- /dev/null +++ b/templates/builder/big.builder @@ -0,0 +1,27 @@ +xml.html do + xml.head do + xml.title 'Customers List' + end + xml.body do + customers.each do |customer| + xml.dl do + xml.dt 'Name:' + xml.dd customer['name'] + xml.dt 'Age:' + xml.dd customer['age'] + xml.dt 'Address:' + xml.dd do + [ + customer['zip'], + customer['country'], + customer['city'], + customer['address'] + ].join("\n") + end + xml.dt 'Employer:' + xml.dd customer['employer'] + end + end + end +end + diff --git a/templates/builder/small.builder b/templates/builder/small.builder new file mode 100644 index 0000000..ddf463c --- /dev/null +++ b/templates/builder/small.builder @@ -0,0 +1,19 @@ +xml.html do + xml.head do + xml.title window_title + end + xml.body do + xml.h1 "Hello, #{username}!" + xml.p do + <<-END + Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod + tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim + veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea + commodo consequat. Duis aute irure dolor in reprehenderit in voluptate + velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint + occaecat cupidatat non proident, sunt in culpa qui officia deserunt + mollit anim id est laborum. + END + end + end +end diff --git a/templates/erb/small.erb b/templates/erb/small.erb index 31abbbd..cac3e38 100644 --- a/templates/erb/small.erb +++ b/templates/erb/small.erb @@ -1,7 +1,7 @@
-