aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Benchmarks/bigtable
diff options
context:
space:
mode:
Diffstat (limited to 'src/Benchmarks/bigtable')
-rw-r--r--src/Benchmarks/bigtable/erb.rb32
-rw-r--r--src/Benchmarks/bigtable/erubis.rb31
-rw-r--r--src/Benchmarks/bigtable/hamlet.hs33
-rw-r--r--src/Benchmarks/bigtable/html-minimalist.hs20
-rw-r--r--src/Benchmarks/bigtable/html.hs19
-rw-r--r--src/Benchmarks/bigtable/php.php30
-rw-r--r--src/Benchmarks/bigtable/xhtml.hs19
7 files changed, 184 insertions, 0 deletions
diff --git a/src/Benchmarks/bigtable/erb.rb b/src/Benchmarks/bigtable/erb.rb
new file mode 100644
index 0000000..c3a675a
--- /dev/null
+++ b/src/Benchmarks/bigtable/erb.rb
@@ -0,0 +1,32 @@
1# BigTable benchmark implemented in ERB.
2#
3require 'erb'
4require 'benchmark'
5include ERB::Util
6
7table = (1 .. 1000).map do |_| (1 .. 10) end
8
9template = ERB.new <<-EOF
10<table>
11 <% table.each do |row| %>
12 <tr>
13 <% row.each do |value| %>
14 <td>
15 <%= value %>
16 </td>
17 <% end %>
18 </tr>
19 <% end %>
20</table>
21EOF
22
23number_runs = 100
24start_time = Time.now.to_f
25number_runs.times do
26 template.result(binding)
27end
28end_time = Time.now.to_f
29
30# start_time and end_time are both in seconds now
31ms = (end_time - start_time) * 1000 / number_runs
32puts "\"ERB\", #{ms}"
diff --git a/src/Benchmarks/bigtable/erubis.rb b/src/Benchmarks/bigtable/erubis.rb
new file mode 100644
index 0000000..9a1edf9
--- /dev/null
+++ b/src/Benchmarks/bigtable/erubis.rb
@@ -0,0 +1,31 @@
1# BigTable benchmark implemented in erubis
2#
3require 'erubis'
4require 'benchmark'
5
6table = (1 .. 1000).map do |_| (1 .. 10) end
7
8template = Erubis::Eruby.new <<-EOF
9<table>
10 <% table.each do |row| %>
11 <tr>
12 <% row.each do |value| %>
13 <td>
14 <%= value %>
15 </td>
16 <% end %>
17 </tr>
18 <% end %>
19</table>
20EOF
21
22number_runs = 100
23start_time = Time.now.to_f
24number_runs.times do
25 template.result(binding)
26end
27end_time = Time.now.to_f
28
29# start_time and end_time are both in seconds now
30ms = (end_time - start_time) * 1000 / number_runs
31puts "\"Erubis\", #{ms}"
diff --git a/src/Benchmarks/bigtable/hamlet.hs b/src/Benchmarks/bigtable/hamlet.hs
new file mode 100644
index 0000000..2778f2d
--- /dev/null
+++ b/src/Benchmarks/bigtable/hamlet.hs
@@ -0,0 +1,33 @@
1-- | BigTable benchmark implemented using Hamlet.
2--
3{-# LANGUAGE QuasiQuotes #-}
4module Main where
5
6import Criterion.Main
7import Text.Hamlet
8import Text.Hamlet.Monad
9import Numeric (showInt)
10import Data.Text (Text)
11import qualified Data.Text as T
12import Data.Maybe (fromJust)
13
14main = defaultMain
15 [ bench "bigTable" $ nf bigTable bigTableData
16 ]
17 where
18 rows :: Int
19 rows = 1000
20
21 bigTableData :: [[Int]]
22 bigTableData = replicate rows [1..10]
23 {-# NOINLINE bigTableData #-}
24
25bigTable rows = fromJust $ hamletToText undefined [$hamlet|
26%table
27 $forall rows row
28 %tr
29 $forall row cell
30 %td $showInt'.cell$
31|]
32 where
33 showInt' i = Encoded $ T.pack $ showInt i ""
diff --git a/src/Benchmarks/bigtable/html-minimalist.hs b/src/Benchmarks/bigtable/html-minimalist.hs
new file mode 100644
index 0000000..2a52751
--- /dev/null
+++ b/src/Benchmarks/bigtable/html-minimalist.hs
@@ -0,0 +1,20 @@
1-- | BigTable benchmark using the html-minimalist package from hackage.
2--
3import Text.HTML.Light hiding (map)
4import Criterion.Main
5
6bigTable :: [[Int]] -> String
7bigTable t =
8 renderXHTML xhtml_1_0_strict $ html [] $ return $ table [] $ map row t
9 where
10 row r = tr [] $ map (td [] . return . cdata . show) r
11
12main = defaultMain
13 [ bench "bigTable" $ nf bigTable myTable ]
14 where
15 rows :: Int
16 rows = 1000
17
18 myTable :: [[Int]]
19 myTable = replicate rows [1..10]
20 {-# NOINLINE myTable #-}
diff --git a/src/Benchmarks/bigtable/html.hs b/src/Benchmarks/bigtable/html.hs
new file mode 100644
index 0000000..57a62b3
--- /dev/null
+++ b/src/Benchmarks/bigtable/html.hs
@@ -0,0 +1,19 @@
1-- | BigTable benchmark using the HTML package from hackage.
2--
3import Text.Html
4import Criterion.Main
5
6bigTable :: [[Int]] -> String
7bigTable t = renderHtml $ table $ concatHtml $ map row t
8 where
9 row r = tr $ concatHtml $ map (td . stringToHtml . show) r
10
11main = defaultMain
12 [ bench "bigTable" $ nf bigTable myTable ]
13 where
14 rows :: Int
15 rows = 1000
16
17 myTable :: [[Int]]
18 myTable = replicate rows [1..10]
19 {-# NOINLINE myTable #-}
diff --git a/src/Benchmarks/bigtable/php.php b/src/Benchmarks/bigtable/php.php
new file mode 100644
index 0000000..f2e51a4
--- /dev/null
+++ b/src/Benchmarks/bigtable/php.php
@@ -0,0 +1,30 @@
1<?php
2$table = array_fill(0, 1000, array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10));
3
4function test_bigtable($table) {
5 ob_start();
6?>
7<table>
8<?php foreach($table as $row) { ?>
9<tr>
10<?php foreach($row as $value) { ?>
11<td><?php echo $value; ?></td>
12<?php } ?>
13</tr>
14<?php } ?>
15</table>
16<?php
17 return ob_get_clean();
18}
19
20$request_count = 1000;
21
22$start = microtime(true);
23for ($i = 0; $i < $request_count; $i++)
24{
25 test_bigtable($table);
26}
27$elapsed = microtime(true) - $start;
28$time_per_request = ($elapsed / $request_count) * 1000;
29echo "\"PHP\", $time_per_request\n";
30?>
diff --git a/src/Benchmarks/bigtable/xhtml.hs b/src/Benchmarks/bigtable/xhtml.hs
new file mode 100644
index 0000000..993994c
--- /dev/null
+++ b/src/Benchmarks/bigtable/xhtml.hs
@@ -0,0 +1,19 @@
1-- | BigTable benchmark using the XHTML package from hackage.
2--
3import Text.XHtml.Strict
4import Criterion.Main
5
6bigTable :: [[Int]] -> String
7bigTable t = renderHtml $ table $ concatHtml $ map row t
8 where
9 row r = tr $ concatHtml $ map (td . stringToHtml . show) r
10
11main = defaultMain
12 [ bench "bigTable" $ nf bigTable myTable ]
13 where
14 rows :: Int
15 rows = 1000
16
17 myTable :: [[Int]]
18 myTable = replicate rows [1..10]
19 {-# NOINLINE myTable #-}