YA String Concat (v29)

Revision 29 of this benchmark created by Nicholas Duvieilh on


Description

Benchmarking string methods given in airbnb's style guide

Preparation HTML

<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/handlebars.js/3.0.3/handlebars.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>

<script id="test-template" type="text/x-handlebars-template">
  This is a super long message about {{person.name.first}}
{{person.name.last}}.  A {{person.age}} year old {{person.sex}}
 that sets a world record height for {{person.height}} in his 
age group of {{person.ageGroup.lower}}-{{person.ageGroup.upper}}
 year olds
</script>

Setup

var person = {
        name: {
            first: 'Bob',
            last: 'Smith'
        },
        age: 25,
        ageGroup: {
            lower: 20,
            upper: 30
        },
        sex: "male",
        height: "5' 8\""
    };

Test runner

Ready to run.

Testing in
TestOps/sec
Long string without breaks
var errorMessage = 'This is a super long message about '+person.name.first+' '+person.name.last+'.  A '+person.age+' year old '+person.sex+' that sets a world record height for '+person.height+' in his age group of '+person.ageGroup.lower+'-'+person.ageGroup.upper+' year olds';
 
ready
Long string without breaks
var errorMessage = 'This is a super long message about '+person.name.first+' '+person.name.last+'.  A '+person.age+' year old '+person.sex+' that sets a world record height for '+person.height+' in his age group of '+person.ageGroup.lower+'-'+person.ageGroup.upper+' year olds';
 
ready
Long string with concats
var errorMessage = 'This is a super long message about '+
person.name.first+
' '+
person.name.last+
'.  A '+
person.age+
' year old '+
person.sex+
' that sets a world record height for '+
person.height+
' in his age group of '+
person.ageGroup.lower+
'-'+
person.ageGroup.upper+
' year olds';
ready
Long string with array join (handlebars)
var source = [
  'This is a super long message about {{person.name.first}}',
'{{person.name.last}}.  A {{person.age}} year old {{person.sex}}',
' that sets a world record height for {{person.height}} in his ',
'age group of {{person.ageGroup.lower}}-{{person.ageGroup.upper}}',
' year olds'
].join('\n');

var errorMessage = Handlebars.compile(source) (person);
ready
Script tag template (handlebars)
var template = $('#test-template').html();
var errorMessage = Handlebars.compile(template) (person);
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.