Skip to content

Commit

Permalink
creating more benchmark data
Browse files Browse the repository at this point in the history
  • Loading branch information
mmmries committed Jan 20, 2014
1 parent 9b1071b commit cd2fbff
Show file tree
Hide file tree
Showing 4 changed files with 342 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ spec/reports
test/tmp
test/version_tmp
tmp
bin/
47 changes: 38 additions & 9 deletions spec/benchmarks.rb
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
require 'bundler/setup'
require 'java_css_inliner'
require 'derelicte'
require 'benchmark'
require 'fileutils'

files_dir = File.join(File.dirname(__FILE__), 'files')
html_file = File.join(files_dir, 'ink_boilerplate.html')
html_file = File.join(files_dir, 'ink_hero.html')
css_file = File.join(files_dir, 'ink.css')
css_file2 = File.join(files_dir, 'ink_hero.css')
html_str = File.read(html_file)
css_str = File.read(css_file)
css_str = File.read(css_file) + File.read(css_file2)

output_dir = File.join(File.dirname(__FILE__), '..', 'tmp')
output_file = File.join(output_dir, 'ink_boilerplate.inlined.html')
output_file = File.join(output_dir, 'ink_hero.inlined.html')
FileUtils.mkdir_p(output_dir)

inliner = CSS::Inliner.new
inliner = Derelicte::Inliner.new

# Get an initial benchmark
Benchmark.bm(40) do |bm|
bm.report('initial run') do
bm.report('initial run (1x)') do
inliner.inline(html_str, css_str)
end
end
Expand All @@ -28,13 +29,41 @@
end

# Warmup the JIT
500.times do
1000.times do
inliner.inline(html_str, css_str)
end

# Benchmark the JIT optimized time
Benchmark.bm(40) do |bm|
bm.report('after warmup') do
inliner.inline(html_str, css_str)
bm.report('after warmup (10x)') do
10.times do
inliner.inline(html_str, css_str)
end
end
end

doc = ::Derelicte.doc_from_str(html_str)
analyzer = ::Derelicte.css_analyzer_from_str(css_str)
job = ::Derelicte::InlinerJob.new(doc, analyzer)
job.send(:assignments)

Benchmark.bm(40) do |bm|
bm.report('parse css to analyzer (10x)') do
10.times do
analyzer = ::Derelicte.css_analyzer_from_str(css_str)
end
end

bm.report('evaluate rules for doc (10x)') do
10.times do
job = ::Derelicte::InlinerJob.new(doc, analyzer)
job.send(:assignments)
end
end

bm.report('apply rules to doc (10x)') do
10.times do
job.apply_rules_to_doc
end
end
end
73 changes: 73 additions & 0 deletions spec/files/ink_hero.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
table.facebook td {
background: #3b5998;
border-color: #2d4473;
}

table.facebook:hover td {
background: #2d4473 !important;
}

table.twitter td {
background: #00acee;
border-color: #0087bb;
}

table.twitter:hover td {
background: #0087bb !important;
}

table.google-plus td {
background-color: #DB4A39;
border-color: #CC0000;
}

table.google-plus:hover td {
background: #CC0000 !important;
}

.template-label {
color: #ffffff;
font-weight: bold;
font-size: 11px;
}

.callout .panel {
background: #ECF8FF;
border-color: #b9e5ff;
}

.header {
background: #999999;
}

.footer .wrapper {
background: #ebebeb;
}

.footer h5 {
padding-bottom: 10px;
}

table.columns .text-pad {
padding-left: 10px;
padding-right: 10px;
}

table.columns .left-text-pad {
padding-left: 10px;
}

table.columns .right-text-pad {
padding-right: 10px;
}

@media only screen and (max-width: 600px) {

table[class="body"] .right-text-pad {
padding-left: 10px !important;
}

table[class="body"] .left-text-pad {
padding-right: 10px !important;
}
}
230 changes: 230 additions & 0 deletions spec/files/ink_hero.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,230 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width"/>
</head>
<body>
<table class="body">
<tr>
<td class="center" align="center" valign="top">
<center>


<table class="row header">
<tr>
<td class="center" align="center">
<center>

<table class="container">
<tr>
<td class="wrapper last">

<table class="twelve columns">
<tr>

<td class="six sub-columns">
<img src="http://placehold.it/200x50"/>
</td>
<td class="six sub-columns last" align="right" style="text-align:right; vertical-align:middle;">
<span class="template-label">HERO</span>
</td>
<td class="expander"></td>

</tr>
</table>

</td>
</tr>
</table>

</center>
</td>
</tr>
</table>
<br/>

<table class="container">
<tr>
<td>

<!-- content start -->
<table class="row">
<tr>
<td class="wrapper last">

<table class="twelve columns">
<tr>
<td>

<h1>Hi, Elijah Baily</h1>
<p class="lead">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et.</p>
<img width="580" height="300" src="http://placehold.it/580x300"/>

</td>
<td class="expander"></td>
</tr>
</table>

</td>
</tr>
</table>

<table class="row callout">
<tr>
<td class="wrapper last">

<table class="twelve columns">
<tr>
<td class="panel">

<p>Phasellus dictum sapien a neque luctus cursus. Pellentesque sem dolor, fringilla et pharetra vitae. <a href="#">Click it! »</a></p>

</td>
<td class="expander"></td>
</tr>
</table>

</td>
</tr>
</table>

<table class="row">
<tr>
<td class="wrapper last">

<table class="twelve columns">
<tr>
<td>

<h3>Title Ipsum <small>This is a note.</small></h3>
<p>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.</p>

</td>
<td class="expander"></td>
</tr>
</table>

</td>
</tr>
</table>


<table class="row">
<tr>
<td class="wrapper last">

<table class="three columns">
<tr>
<td>

<table class="button">
<tr>
<td>
<a href="#">Click Me!</a>
</td>
</tr>
</table>

</td>
<td class="expander"></td>
</tr>
</table>

</td>
</tr>
</table>


<table class="row footer">
<tr>
<td class="wrapper">

<table class="six columns">
<tr>
<td class="left-text-pad">

<h5>Connect With Us:</h5>

<table class="tiny-button facebook">
<tr>
<td>
<a href="#">Facebook</a>
</td>
</tr>
</table>

<br/>

<table class="tiny-button twitter">
<tr>
<td>
<a href="#">Twitter</a>
</td>
</tr>
</table>

<br/>

<table class="tiny-button google-plus">
<tr>
<td>
<a href="#">Google +</a>
</td>
</tr>
</table>

</td>
<td class="expander"></td>
</tr>
</table>

</td>
<td class="wrapper last">

<table class="six columns">
<tr>
<td class="last right-text-pad">
<h5>Contact Info:</h5>
<p>Phone: 408.341.0600</p>
<p>Email: <a href="mailto:hseldon@trantor.com">hseldon@trantor.com</a></p>
</td>
<td class="expander"></td>
</tr>
</table>

</td>
</tr>
</table>


<table class="row">
<tr>
<td class="wrapper last">

<table class="twelve columns">
<tr>
<td align="center">
<center>
<p style="text-align:center;"><a href="#">Terms</a> | <a href="#">Privacy</a> | <a href="#">Unsubscribe</a></p>
</center>
</td>
<td class="expander"></td>
</tr>
</table>

</td>
</tr>
</table>

<!-- container end below -->
</td>
</tr>
</table>

</center>
</td>
</tr>
</table>
</body>
</html>

0 comments on commit cd2fbff

Please sign in to comment.