Created
March 2, 2014 18:29
-
-
Save evgenius/9311237 to your computer and use it in GitHub Desktop.
A test for optimization of the "for" tag (Twig.js)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Twig = require('./twig'); | |
var context = {}; | |
// Context is big | |
for (var i=0; i<500; i++) { | |
context[''+i] = i; | |
} | |
// List of countries | |
var countries = context.countries = {}; | |
for (var i=0; i<200; i++) { | |
countries[''+i] = i; | |
} | |
var data = '{% for country_code, country_name in countries %}{{ country_code }} - {{ country_name }}\n{% endfor %}'; | |
// Let's render a list of countries, say, 2^3 times | |
for (var i=0; i<3; i++) { | |
data += data; | |
} | |
console.time('render'); | |
console.log(Twig.twig({data: data}).render(context)); | |
console.timeEnd('render'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment