diff options
Diffstat (limited to 'src/Benchmarks/bigtable')
-rw-r--r-- | src/Benchmarks/bigtable/erb.rb | 32 | ||||
-rw-r--r-- | src/Benchmarks/bigtable/erubis.rb | 31 | ||||
-rw-r--r-- | src/Benchmarks/bigtable/hamlet.hs | 33 | ||||
-rw-r--r-- | src/Benchmarks/bigtable/html-minimalist.hs | 20 | ||||
-rw-r--r-- | src/Benchmarks/bigtable/html.hs | 19 | ||||
-rw-r--r-- | src/Benchmarks/bigtable/php.php | 30 | ||||
-rw-r--r-- | src/Benchmarks/bigtable/xhtml.hs | 19 |
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 | # | ||
3 | require 'erb' | ||
4 | require 'benchmark' | ||
5 | include ERB::Util | ||
6 | |||
7 | table = (1 .. 1000).map do |_| (1 .. 10) end | ||
8 | |||
9 | template = 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> | ||
21 | EOF | ||
22 | |||
23 | number_runs = 100 | ||
24 | start_time = Time.now.to_f | ||
25 | number_runs.times do | ||
26 | template.result(binding) | ||
27 | end | ||
28 | end_time = Time.now.to_f | ||
29 | |||
30 | # start_time and end_time are both in seconds now | ||
31 | ms = (end_time - start_time) * 1000 / number_runs | ||
32 | puts "\"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 | # | ||
3 | require 'erubis' | ||
4 | require 'benchmark' | ||
5 | |||
6 | table = (1 .. 1000).map do |_| (1 .. 10) end | ||
7 | |||
8 | template = 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> | ||
20 | EOF | ||
21 | |||
22 | number_runs = 100 | ||
23 | start_time = Time.now.to_f | ||
24 | number_runs.times do | ||
25 | template.result(binding) | ||
26 | end | ||
27 | end_time = Time.now.to_f | ||
28 | |||
29 | # start_time and end_time are both in seconds now | ||
30 | ms = (end_time - start_time) * 1000 / number_runs | ||
31 | puts "\"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 #-} | ||
4 | module Main where | ||
5 | |||
6 | import Criterion.Main | ||
7 | import Text.Hamlet | ||
8 | import Text.Hamlet.Monad | ||
9 | import Numeric (showInt) | ||
10 | import Data.Text (Text) | ||
11 | import qualified Data.Text as T | ||
12 | import Data.Maybe (fromJust) | ||
13 | |||
14 | main = 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 | |||
25 | bigTable 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 | -- | ||
3 | import Text.HTML.Light hiding (map) | ||
4 | import Criterion.Main | ||
5 | |||
6 | bigTable :: [[Int]] -> String | ||
7 | bigTable 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 | |||
12 | main = 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 | -- | ||
3 | import Text.Html | ||
4 | import Criterion.Main | ||
5 | |||
6 | bigTable :: [[Int]] -> String | ||
7 | bigTable t = renderHtml $ table $ concatHtml $ map row t | ||
8 | where | ||
9 | row r = tr $ concatHtml $ map (td . stringToHtml . show) r | ||
10 | |||
11 | main = 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 | |||
4 | function 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); | ||
23 | for ($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; | ||
29 | echo "\"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 | -- | ||
3 | import Text.XHtml.Strict | ||
4 | import Criterion.Main | ||
5 | |||
6 | bigTable :: [[Int]] -> String | ||
7 | bigTable t = renderHtml $ table $ concatHtml $ map row t | ||
8 | where | ||
9 | row r = tr $ concatHtml $ map (td . stringToHtml . show) r | ||
10 | |||
11 | main = 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 #-} | ||