Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
require 'bundler/setup'
require 'benchmark'
require 'escape_utils'
require 'cgi'
examples = {
'small' => 'โค<a href="harmless">',
'medium' => '<div class="search"> <form id="tag-search-form"> <input id="tag-search-input" class="search-input placeholder" type="text" placeholder="emoji"/> <span class="search-icon"></span> <span class="search-clear"></span> <div id="categories-list" class="sorting"> <ul id="tag-search-results" class="poll-categories" class="hide"></ul> <ul id="suggested-categories" class="poll-categories"> <li><a href="" class="poll-category" data-category="tag" data-name="ios7beta">ios7beta</a></li> <li><a href="" class="poll-category" data-category="tag" data-name="starwarslife">starwarslife</a></li> <li><a href="" class="poll-category" data-category="tag" data-name="tvduos">tvduos</a></li> <li><a href="" class="poll-category" data-category="tag" data-name="rathermeet">rathermeet</a></li> <li><a href="" class="poll-category" data-category="tag" data-name="dcvsmarvel">dcvsmarvel</a></li> </ul> </div> </form> </div>',
'large' => '<div id="main-container" class="main-container"> <div class="middle-gutter"> <div class="bears"> <div class="bears-app-download"> <a href="https://itunes.apple.com/app/polar/id563322683" class=""></a> </div> </div> </div> <div id="polls"> <section id="polls-section"> <div class="keyboard-shortcuts"> <ul class="shortcut-items hidden"> <li>&uarr; previous poll</li> <li>&darr; next poll</li> <li>&larr; vote left</li> <li>&rarr; vote right</li> </ul> </div> <header> <div class="profile-wrap wrapper"> <div class="avatar-wrap"> </div> <div class="profile-info"> </div> </div> </header> <div id="main-polls-wrap"> <ul class="polls"> <li id="poll-115328" class="pollbox"> <div class="pollbox-wrap"> <div class="polltop"> <cite><a href="&#47;users&#47;wpeterson">wpeterson</a> Asks</cite> <a href="&#47;users&#47;wpeterson"><img src="http:&#47;&#47;avatars-polarb-com.a.ssl.fastly.net&#47;000&#47;012&#47;318&#47;12318-small_retina-68e99cfe25deef78.jpg" border="0" /></a> <h2 class="poll-question"><a href="/115328">Do You <img class="emoji" src="http://assets-polarb-com.a.ssl.fastly.net/assets/emoji/heart.png"> Emoji Polls?</a></h2> </div> <div class="pollvotesbox"> <span class="pollor">Or</span> <ul class="pollvotes"> <li class="polloption polloption1" data-choice="1" data-pollid="115328">Yes <img class="emoji" src="http://assets-polarb-com.a.ssl.fastly.net/assets/emoji/heart.png"></li> <li class="polloption polloption2" data-choice="2" data-pollid="115328">No <img class="emoji" src="http://assets-polarb-com.a.ssl.fastly.net/assets/emoji/poop.png"></li> </ul> <span class="pollleft"></span> <span class="pollright"></span> </div><!-- end ./pollvotesbox --> <div class="pollimgbox"> <ul class="pollimgvotes"> <li> <a class="pollimgvote pollimgvote1" data-choice="1" data-pollid="115328"></a> <div class="pollimgresult pollimgresult1" data-choice="1" data-pollid="115328"><span class="votecount1" style="">54</span></div> </li> <li> <a class="pollimgvote pollimgvote2" data-choice="2" data-pollid="115328"></a> <div class="pollimgresult pollimgresult2" data-choice="2" data-pollid="115328"><span class="votecount2" style="">46</span></div> </li> </ul> <img src="http:&#47;&#47;polls-polarb-com.a.ssl.fastly.net&#47;000&#47;115&#47;328&#47;115328-1-large-d499d55a833dd6ca.jpg" alt="Do You <img class="emoji" src="http://assets-polarb-com.a.ssl.fastly.net/assets/emoji/heart.png"> Emoji Polls?"> </div><!-- end ./pollimgbox --> <ul class="pollactions group"> <li><a href="https:&#47;&#47;itunes.apple.com&#47;app&#47;polar&#47;id563322683?ls=1&amp;mt=8"><span class="pollcomment"></span>Comment</a></li> <li class="pollactionslast"><a href="/115328"><span class="pollresults"></span>Share</a></li> </ul> <ul class="pollcomments group"> <li><strong>wpeterson</strong> OK. Web emoji fixed in poll comments, too.</li> <li><strong>peort30</strong> <img class="emoji" src="http://assets-polarb-com.a.ssl.fastly.net/assets/emoji/smiley.png"><img class="emoji" src="http://assets-polarb-com.a.ssl.fastly.net/assets/emoji/smiley.png"><img class="emoji" src="http://assets-polarb-com.a.ssl.fastly.net/assets/emoji/smile.png"><img class="emoji" src="http://assets-polarb-com.a.ssl.fastly.net/assets/emoji/smile.png"><img class="emoji" src="http://assets-polarb-com.a.ssl.fastly.net/assets/emoji/grinning.png"><img class="emoji" src="http://assets-polarb-com.a.ssl.fastly.net/assets/emoji/grinning.png"></li> <li><strong>polar</strong> <img class="emoji" src="http://assets-polarb-com.a.ssl.fastly.net/assets/emoji/penguin.png"></li> <li><a href="/115328">See more</a></li> </ul> </div><!-- end ./pollbox-wrap --> </li> <li id="poll-112694" class="pollbox"> <div class="pollbox-wrap"> <div class="polltop"> <cite><a href="&#47;users&#47;itjennytime">itjennytime</a> Asks</cite> <a href="&#47;users&#47;itjennytime"><img src="http:&#47;&#47;avatars-polarb-com.a.ssl.fastly.net&#47;000&#47;014&#47;311&#47;14311-small_retina-f307a46e42763d9e.jpg" border="0" /></a> <h2 class="poll-question"><a href="/112694">Anyone Know The Answer?</a></h2> </div> <div class="pollvotesbox"> <span class="pollor">Or</span> <ul class="pollvotes"> <li class="polloption polloption1" data-choice="1" data-pollid="112694">Dont Use Emoji Pro</li> <li class="polloption polloption2" data-choice="2" data-pollid="112694">Yes! (comment)</li> </ul> <span class="pollleft"></span> <span class="pollright"></span> </div><!-- end ./pollvotesbox --> <div class="pollimgbox"> <ul class="pollimgvotes"> <li> <a class="pollimgvote pollimgvote1" data-choice="1" data-pollid="112694"></a> <div class="pollimgresult pollimgresult1" data-choice="1" data-pollid="112694"><span class="votecount1" style="">19</span></div> </li> <li> <a class="pollimgvote pollimgvote2" data-choice="2" data-pollid="112694"></a> <div class="pollimgresult pollimgresult2" data-choice="2" data-pollid="112694"><span class="votecount2" style="">6</span></div> </li> </ul> <img src="http:&#47;&#47;polls-polarb-com.a.ssl.fastly.net&#47;000&#47;112&#47;694&#47;112694-1-large-d5ab0dbe08ec47ee.jpg" alt="Anyone Know The Answer?"> </div><!-- end ./pollimgbox --> <ul class="pollactions group"> <li><a href="https:&#47;&#47;itunes.apple.com&#47;app&#47;polar&#47;id563322683?ls=1&amp;mt=8"><span class="pollcomment"></span>Comment</a></li> <li class="pollactionslast"><a href="/112694"><span class="pollresults"></span>Share</a></li> </ul> <ul class="pollcomments group"> <li><strong>itjennytime</strong> <a class="" href="/polls/tags/emoji" title="#emoji">#emoji</a></li> <li><strong>doodledump</strong> Mailman</li> </ul> </div><!-- end ./pollbox-wrap --> </li> <li id="poll-110180" class="pollbox"> <div class="pollbox-wrap"> <div class="polltop"> <cite><a href="&#47;users&#47;blittle202">blittle202</a> Asks</cite> <a href="&#47;users&#47;blittle202"><img src="http:&#47;&#47;avatars-polarb-com.a.ssl.fastly.net&#47;000&#47;015&#47;302&#47;15302-small_retina-c3c4001165c0f65b.jpg" border="0" /></a> <h2 class="poll-question"><a href="/110180">What Is This Emoji?</a></h2> </div> <div class="pollvotesbox"> <span class="pollor">Or</span> <ul class="pollvotes"> <li class="polloption polloption1" data-choice="1" data-pollid="110180">Someone Praying</li> <li class="polloption polloption2" data-choice="2" data-pollid="110180">A High Five</li> </ul> <span class="pollleft"></span> <span class="pollright"></span> </div><!-- end ./pollvotesbox --> <div class="pollimgbox"> <ul class="pollimgvotes"> <li> <a class="pollimgvote pollimgvote1" data-choice="1" data-pollid="110180"></a> <div class="pollimgresult pollimgresult1" data-choice="1" data-pollid="110180"><span class="votecount1" style="">77</span></div> </li> <li> <a class="pollimgvote pollimgvote2" data-choice="2" data-pollid="110180"></a> <div class="pollimgresult pollimgresult2" data-choice="2" data-pollid="110180"><span class="votecount2" style="">17</span></div> </li> </ul> <img src="http:&#47;&#47;polls-polarb-com.a.ssl.fastly.net&#47;000&#47;110&#47;180&#47;110180-1-large-d676f16beaa73807.jpg" alt="What Is This Emoji?"> </div><!-- end ./pollimgbox --> <ul class="pollactions group"> <li><a href="https:&#47;&#47;itunes.apple.com&#47;app&#47;polar&#47;id563322683?ls=1&amp;mt=8"><span class="pollcomment"></span>Comment</a></li> <li class="pollactionslast"><a href="/110180"><span class="pollresults"></span>Share</a></li> </ul> <ul class="pollcomments group"> <li><strong>blittle202</strong> <a class="" href="/polls/tags/emojis" title="#emojis">#emojis</a></li> <li><strong>tylermeca</strong> Could be both</li> <li><strong>blittle202</strong> Yes but what do you think it is</li> </ul> </div><!-- end ./pollbox-wrap --> </li> <li id="poll-100608" class="pollbox"> <div class="pollbox-wrap"> <div class="polltop"> <cite><a href="&#47;users&#47;emily20soccer">emily20soccer</a> Asks</cite> <a href="&#47;users&#47;emily20soccer"><img src="http:&#47;&#47;avatars-polarb-com.a.ssl.fastly.net&#47;000&#47;018&#47;308&#47;18308-small_retina-37f97ab5be3b047c.jpg" border="0" /></a> <h2 class="poll-question"><a href="/100608">Do You Love Emoji? If So Comment Your Fav Below!</a></h2> </div> <div class="pollvotesbox"> <span class="pollor">Or</span> <ul class="pollvotes"> <li class="polloption polloption1" data-choice="1" data-pollid="100608">Yes</li> <li class="polloption polloption2" data-choice="2" data-pollid="100608">No</li> </ul> <span class="pollleft"></span> <span class="pollright"></span> </div><!-- end ./pollvotesbox --> <div class="pollimgbox"> <ul class="pollimgvotes"> <li> <a class="pollimgvote pollimgvote1" data-choice="1" data-pollid="100608"></a> <div class="pollimgresult pollimgresult1" data-choice="1" data-pollid="100608"><span class="votecount1" style="">63</span></div> </li> <li> <a class="pollimgvote pollimgvote2" data-choice="2" data-pollid="100608"></a> <div class="pollimgresult pollimgresult2" data-choice="2" data-pollid="100608"><span class="votecount2" style="">25</span></div> </li> </ul> <img src="http:&#47;&#47;polls-polarb-com.a.ssl.fastly.net&#47;000&#47;100&#47;608&#47;100608-1-large-ac7c780039a18f75.jpg" alt="Do You Love Emoji? If So Comment Your Fav Below!"> </div><!-- end ./pollimgbox --> <ul class="pollactions group"> <li><a href="https:&#47;&#47;itunes.apple.com&#47;app&#47;polar&#47;id563322683?ls=1&amp;mt=8"><span class="pollcomment"></span>Comment</a></li> <li class="pollactionslast"><a href="/100608"><span class="pollresults"></span>Share</a></li> </ul> <ul class="pollcomments group"> <li><strong>bulbie</strong> ๐Ÿ˜ฑ๐Ÿ˜ฑ๐Ÿ˜ฑ๐Ÿ˜ฑ๐Ÿ˜ฑ๐Ÿ˜ฑ๐Ÿ˜ฑ๐Ÿ˜ฑ๐Ÿ˜ฑ๐Ÿ˜ฑ๐Ÿ˜ฑ</li> <li><strong>MineCraftWes</strong> <img class="emoji" src="http://assets-polarb-com.a.ssl.fastly.net/assets/emoji/high_voltage_sign.png"><img class="emoji" src="http://assets-polarb-com.a.ssl.fastly.net/assets/emoji/smile.png">โšพ<img class="emoji" src="http://assets-polarb-com.a.ssl.fastly.net/assets/emoji/dog_face.png">๐Ÿ˜Ž๐Ÿ’Ž<img class="emoji" src="http://assets-polarb-com.a.ssl.fastly.net/assets/emoji/pistol.png">๐Ÿ’ฃ๐Ÿ‘พ<img class="emoji" src="http://assets-polarb-com.a.ssl.fastly.net/assets/emoji/video_game.png">๐Ÿ‡บ๐Ÿ‡ธ<img class="emoji" src="http://assets-polarb-com.a.ssl.fastly.net/assets/emoji/Leo.png"></li> <li><strong>itjennytime</strong> ๐Ÿˆ๐Ÿ†โšพ<img class="emoji" src="http://assets-polarb-com.a.ssl.fastly.net/assets/emoji/microphone.png">๐ŸŽผ๐ŸŽฌ๐ŸŽท<img class="emoji" src="http://assets-polarb-com.a.ssl.fastly.net/assets/emoji/video_game.png">๐Ÿ’ธ</li> <li><a href="/100608">See more</a></li> </ul> </div><!-- end ./pollbox-wrap --> </li> <li id="poll-98033" class="pollbox"> <div class="pollbox-wrap"> <div class="polltop"> <cite><a href="&#47;users&#47;one_direction">one_direction</a> Asks</cite> <a href="&#47;users&#47;one_direction"><img src="http:&#47;&#47;avatars-polarb-com.a.ssl.fastly.net&#47;000&#47;016&#47;614&#47;16614-small_retina-e6795a71ebd97a21.jpg" border="0" /></a> <h2 class="poll-question"><a href="/98033">Do U Use Emojis?</a></h2> </div> <div class="pollvotesbox"> <span class="pollor">Or</span> <ul class="pollvotes"> <li class="polloption polloption1" data-choice="1" data-pollid="98033">Yes</li> <li class="polloption polloption2" data-choice="2" data-pollid="98033">No</li> </ul> <span class="pollleft"></span> <span class="pollright"></span> </div><!-- end ./pollvotesbox --> <div class="pollimgbox"> <ul class="pollimgvotes"> <li> <a class="pollimgvote pollimgvote1" data-choice="1" data-pollid="98033"></a> <div class="pollimgresult pollimgresult1" data-choice="1" data-pollid="98033"><span class="votecount1" style="">86</span></div> </li> <li> <a class="pollimgvote pollimgvote2" data-choice="2" data-pollid="98033"></a> <div class="pollimgresult pollimgresult2" data-choice="2" data-pollid="98033"><span class="votecount2" style="">23</span></div> </li> </ul> <img src="http:&#47;&#47;polls-polarb-com.a.ssl.fastly.net&#47;000&#47;098&#47;033&#47;98033-1-large-a7224fdd495cd33d.jpg" alt="Do U Use Emojis?"> </div><!-- end ./pollimgbox --> <ul class="pollactions group"> <li><a href="https:&#47;&#47;itunes.apple.com&#47;app&#47;polar&#47;id563322683?ls=1&amp;mt=8"><span class="pollcomment"></span>Comment</a></li> <li class="pollactionslast"><a href="/98033"><span class="pollresults"></span>Share</a></li> </ul> <ul class="pollcomments group"> <li><strong>fashionista</strong> ๐Ÿ‡ฉ๐Ÿ‡ช1โƒฃ2โƒฃ3โƒฃ4โƒฃ5โƒฃ6โƒฃ7โƒฃ8โƒฃ9โƒฃ0โƒฃ#โƒฃโฌ†โฌ‡โฌ…โžกโ†—โ†–โ†˜โ†™โ—€โ–ถโชโฉ๐Ÿ†—๐Ÿ†•๐Ÿ”๐Ÿ†™๐Ÿ†’๐ŸŽฆ๐Ÿˆ๐Ÿ“ถ๐Ÿˆต๐Ÿˆณ๐Ÿ‰๐Ÿˆน๐Ÿˆฏ๐Ÿˆบ๐Ÿˆถ๐Ÿˆš๐Ÿˆท๐Ÿˆธ๐Ÿˆ‚๐Ÿšป<img class="emoji" src="http://assets-polarb-com.a.ssl.fastly.net/assets/emoji/mens_symbol.png">๐Ÿšบ๐Ÿšผ๐Ÿšญ๐Ÿ…ฟ<img class="emoji" src="http://assets-polarb-com.a.ssl.fastly.net/assets/emoji/wheelchair.png">๐Ÿš‡๐Ÿšพ<img class="emoji" src="http://assets-polarb-com.a.ssl.fastly.net/assets/emoji/circled_ideograph_secret.png">ใŠ—<img class="emoji" src="http://assets-polarb-com.a.ssl.fastly.net/assets/emoji/no_one_under_eighteen_symbol.png">๐Ÿ†”โœณโœด๐Ÿ’Ÿ๐Ÿ†š๐Ÿ“ณ๐Ÿ“ด๐Ÿ’น๐Ÿ’ฑ<img class="emoji" src="http://assets-polarb-com.a.ssl.fastly.net/assets/emoji/Aries.png"><img class="emoji" src="http://assets-polarb-com.a.ssl.fastly.net/assets/emoji/Taurus.png"><img class="emoji" src="http://assets-polarb-com.a.ssl.fastly.net/assets/emoji/Gemini.png"><img class="emoji" src="http://assets-polarb-com.a.ssl.fastly.net/assets/emoji/Cancer.png"><img class="emoji" src="http://assets-polarb-com.a.ssl.fastly.net/assets/emoji/Leo.png"><img class="emoji" src="http://assets-polarb-com.a.ssl.fastly.net/assets/emoji/Virgo.png"><img class="emoji" src="http://assets-polarb-com.a.ssl.fastly.net/assets/emoji/Libra.png"><img class="emoji" src="http://assets-polarb-com.a.ssl.fastly.net/assets/emoji/Scorpius.png"><img class="emoji" src="http://assets-polarb-com.a.ssl.fastly.net/assets/emoji/Sagittarius.png"><img class="emoji" src="http://assets-polarb-com.a.ssl.fastly.net/assets/emoji/Capricorn.png"><img class="emoji" src="http://assets-polarb-com.a.ssl.fastly.net/assets/emoji/Aquarius.png"><img class="emoji" src="http://assets-polarb-com.a.ssl.fastly.net/assets/emoji/Pisces.png">โ›Ž๐Ÿ”ฏ๐Ÿ…ฐ๐Ÿ…ฑ๐Ÿ†Ž๐Ÿ…พ๐Ÿ”ฒ๐Ÿ”ด</li> <li><strong>fashionista</strong> ๐Ÿ•›๐Ÿ•๐Ÿ•‘๐Ÿ•’๐Ÿ•“๐Ÿ•”๐Ÿ••๐Ÿ•–๐Ÿ•—๐Ÿ•˜๐Ÿ•™๐Ÿ•šโญ•โŒยฉยฎโ„ข</li> <li><strong>Ricky-el</strong> <a class="" href="/users/fashionista">@fashionista</a> you flood all polar lol</li> <li><a href="/98033">See more</a></li> </ul> </div><!-- end ./pollbox-wrap --> </li> <li id="no-polls-img" class="no-polls" style="display: none;"><h4>Eek! You caught me with no Polls on.</h4><p id="no-polls-msg">Be a dear and find some polls in the search box for me?</p></li> <li class="to-top"> <p class="to-top-button polls-last"><a href="">top</a></p> </li> </ul> </div> <!-- end --> </section> </div></div> <!-- #main-container -->'
}
%w(small medium large).each do |example_size|
puts "=========================================="
puts "#{example_size.capitalize} Example String"
puts "=========================================="
Benchmark.bmbm do |bm|
bm.report('EscapeUtils.escape_html') { 1000.times { EscapeUtils.escape_html(examples[example_size]) } }
bm.report('CGI.escape_html') { 1000.times { CGI.escape_html(examples[example_size]) } }
end
end
[feature/escape_utils ~/src/emoji]$> b ruby ./escape_utils_bench.rb
==========================================
Small Example String
==========================================
Rehearsal -----------------------------------------------------------
EscapeUtils.escape_html 0.000000 0.000000 0.000000 ( 0.000887)
CGI.escape_html 0.010000 0.000000 0.010000 ( 0.007886)
-------------------------------------------------- total: 0.010000sec
user system total real
EscapeUtils.escape_html 0.000000 0.000000 0.000000 ( 0.000906)
CGI.escape_html 0.000000 0.000000 0.000000 ( 0.003874)
==========================================
Medium Example String
==========================================
Rehearsal -----------------------------------------------------------
EscapeUtils.escape_html 0.010000 0.000000 0.010000 ( 0.006916)
CGI.escape_html 0.090000 0.000000 0.090000 ( 0.092979)
-------------------------------------------------- total: 0.100000sec
user system total real
EscapeUtils.escape_html 0.000000 0.000000 0.000000 ( 0.006635)
CGI.escape_html 0.080000 0.000000 0.080000 ( 0.088211)
==========================================
Large Example String
==========================================
Rehearsal -----------------------------------------------------------
EscapeUtils.escape_html 0.090000 0.010000 0.100000 ( 0.094692)
CGI.escape_html 1.110000 0.000000 1.110000 ( 1.118752)
-------------------------------------------------- total: 1.210000sec
user system total real
EscapeUtils.escape_html 0.080000 0.010000 0.090000 ( 0.090249)
CGI.escape_html 1.090000 0.000000 1.090000 ( 1.099880)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You canโ€™t perform that action at this time.