GithubHelp home page GithubHelp logo

Comments (5)

childe avatar childe commented on July 19, 2024

In my test running at macbook pro I5 2.6G, python code runs in 0.9s, and java 2.5s.

from jinjava.

jaredstehler avatar jaredstehler commented on July 19, 2024

You can create a parsed representation of a template using the interpreter instance, as follows:

    JinjavaInterpreter interpreter = new JinjavaInterpreter(jinjava, jinjava.getGlobalContext(), jinjava.getGlobalConfig());
    Node parsedTemplate = interpreter.parse(template);

    s = System.currentTimeMillis();

    for (int i = 0; i < 70000; i++) {
      interpreter.render(parsedTemplate, true);
    }

This actually runs in 1/3 of the time of your other java example, which is promising! 😄 I'm going to create a nicer factory method of getting a new interpreter instance from a Jinjava object.

from jinjava.

jaredstehler avatar jaredstehler commented on July 19, 2024

Results of updated benchmark code with precompiled (e6dbd9d):

Result: 148.433 ±(99.9%) 2.078 ops/s [Average]
  Statistics: (min, avg, max) = (77.945, 148.433, 158.897), stdev = 8.798
  Confidence interval (99.9%): [146.355, 150.511]


# Run complete. Total time: 00:27:09

Benchmark                                                Mode  Samples     Score     Error  Units
c.h.j.b.jinja2.Jinja2Benchmark.precompiledBenchmark     thrpt      200  9951.372 ± 203.122  ops/s
c.h.j.b.jinja2.Jinja2Benchmark.realWorldishBenchmark    thrpt      200  1160.294 ±  15.803  ops/s
c.h.j.b.liquid.LiquidBenchmark.parse                    thrpt      200  1657.029 ±  23.344  ops/s
c.h.j.b.liquid.LiquidBenchmark.parseAndRender           thrpt      200   148.433 ±   2.078  ops/s

from jinjava.

childe avatar childe commented on July 19, 2024

Yes, it is much faster than before~
But our java version is 1.7 unfortunately, so i have to use jinjava 1.0.9. Maybe that is why is runs 1/2 of the time of previous example.
Thank you all very much!

from jinjava.

childe avatar childe commented on July 19, 2024

before I could create Node , I need a interpreter , but context of the interpreter varies every time, so use below method is better:

        TokenParser t =  new TokenParser(null,template);
        Node parsedTemplate =TreeParser.parseTree(t);
        String s = interpreter.render(parsedTemplate);

from jinjava.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.