Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is the "huge loop" benchmark measuring what it intends? #606

Closed
epage opened this issue Feb 27, 2021 · 1 comment
Closed

Is the "huge loop" benchmark measuring what it intends? #606

epage opened this issue Feb 27, 2021 · 1 comment

Comments

@epage
Copy link

epage commented Feb 27, 2021

I was taking inspiration from Tera's benchmarks for Liquid but huge_loop seems off unless I'm misunderstanding Tera or Handlebars.

    let rows = RowWrapper { real, dummy };

    let mut tera = Tera::default();
    tera.add_raw_templates(vec![("huge.html", "{% for v in rows %}{{v}}{% endfor %}")]).unwrap();
    let mut context = Context::new();
    context.insert("rows", &rows);

Here, it is iterating on the rows object which has two elements.

From another Issue it sounds like this is meant to mirror handlebars

    handlebars
        .register_template_string("test", "BEFORE\n{{#each real}}{{this.v}}{{/each}}AFTER")
        .ok()
        .expect("Invalid template format");

    let real: Vec<DataWrapper> = (1..1000)
        .map(|i| DataWrapper {
            v: format!("n={}", i),
        })
        .collect();
    let dummy: Vec<DataWrapper> = (1..1000)
        .map(|i| DataWrapper {
            v: format!("n={}", i),
        })
        .collect();
    let rows = RowWrapper { real, dummy };

    let ctx = Context::wraps(&rows).unwrap();
    c.bench_function("large_loop_helper", move |b| {
        b.iter(|| handlebars.render_with_context("test", &ctx).ok().unwrap())
    });

Here I believe rows is the root object in the context so the template variable real maps to the Rust variable rows.real which is an array of 1000 DataWrappers.

@Keats
Copy link
Owner

Keats commented Feb 27, 2021

Yep, it looks like it should do {% for real in rows.real %}{{real.v}}

@Keats Keats closed this as completed in f06e905 Mar 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants