0

i've got a webscript in alfresco which is written in javascript. In this webscript i have a lot of recursion (foreach loops) to do to generate the values that are used by a freemarker template to build a JSON. The problem is that javascript is very slow (3700 milliseconds). I could achieve the same results by iterating in freemarker, but i don't know if it's worth the hassle writing complex loop in freemarker because i don't know if it's faster and i don't know how to benchmark it.

Anyone knows if freemarker is faster than javascript or does anyone knows how to benchmark freemarker?

Nicola Peluchetti
  • 72,169
  • 29
  • 129
  • 186

3 Answers3

3

Some days ago somebody mentioned on the freemarker-devel mailing list that he benchmarked FreeMarker vs. GSP (Groovy Server Pages?). Maybe you can reuse some of his benchmarking stuff. There are some links in his mailing list posting.

Chaquotay
  • 2,102
  • 1
  • 16
  • 22
2

If you want to compare for with forEach, some benchmarks are shown here .

You might want to set your own benchmark in jsperf

fusion
  • 1,164
  • 7
  • 12
1

If performance is an issue, you could try writing your webscript in Java instead. It's not too hard to do, and there are some examples.

One of the examples even shows how to output the JSON from Java, skipping the freemarker layer, which might help you if you want it to run as fast as possible.

Gagravarr
  • 43,370
  • 9
  • 94
  • 140
  • This sounds strange, because we've hired some alfresco "seniors" and they stated that javascript was faster than java. in your expirience java is faster than javascript? – Nicola Peluchetti Jun 12 '11 at 19:20
  • Writing the JavaScript is likely to be faster than writing the Java, that's one of the reasons why most people tend to prefer JS for extensions. For running it, I'd expect Java to be faster. There's a reason that the core of Alfresco is written in Java! – Gagravarr Jun 13 '11 at 00:43