Skip to content

Instantly share code, notes, and snippets.

@evgenius
Created March 2, 2014 18:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evgenius/9311237 to your computer and use it in GitHub Desktop.
Save evgenius/9311237 to your computer and use it in GitHub Desktop.
A test for optimization of the "for" tag (Twig.js)
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