Skip to content

Instantly share code, notes, and snippets.

@evgenius
Created Mar 2, 2014
Embed
What would you like to do?
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