I have a lot of html-blocks in my application, which are used in many templates. But I can not find a good option for load this html-blocks in terms of convenience and speed.
I've found five variants, how to do it: 1) https://gist.github.com/ravengerUA/9725337 (Boilerplate code) - I have to copy my html markup in each template. It's terrible 2) https://gist.github.com/ravengerUA/9725420 (Reusable template blocks) - Good, but I can't add this blocks into another template. Also boilerplate code, but easy to do a copy-paste. 3) https://gist.github.com/ravengerUA/9725511 (Helper with raw markup) - Fast, but ugly. I want to use templates for markup, not code. 4) https://gist.github.com/ravengerUA/9725653 (Helper with render) - Much slower version, but nice. 5) https://gist.github.com/ravengerUA/9730108 (Include + stash) - Also a very slow version. I've benchmarked these versions with this test code https://gist.github.com/ravengerUA/9730638 and have got the results helper_raw: 2 wallclock secs ( 2.33 usr + 0.02 sys = 2.35 CPU) @ 2127.66/s (n=5000) helper_render: 51 wallclock secs (49.28 usr + 1.50 sys = 50.78 CPU) @ 98.46/s (n=5000) include: 53 wallclock secs (51.21 usr + 1.41 sys = 52.62 CPU) @ 95.02/s (n=5000) plain: 2 wallclock secs ( 2.13 usr + 0.03 sys = 2.16 CPU) @ 2314.81/s (n=5000) rtb: 4 wallclock secs ( 3.44 usr + 0.06 sys = 3.50 CPU) @ 1428.57/s (n=5000) I tried to use much faster template engine - Xslate. And created another benchmark: https://gist.github.com/ravengerUA/9743508 helper_raw: 28 wallclock secs (27.84 usr + 0.03 sys = 27.87 CPU) @ 1794.04/s (n=50000) helper_render: 182 wallclock secs (180.90 usr + 0.08 sys = 180.98 CPU) @ 276.27/s (n=50000) include: 5 wallclock secs ( 5.75 usr + 0.00 sys = 5.75 CPU) @ 8695.65/s (n=50000) plain: 3 wallclock secs ( 3.49 usr + 0.01 sys = 3.50 CPU) @ 14285.71/s (n=50000) rtb: 6 wallclock secs ( 5.52 usr + 0.01 sys = 5.53 CPU) @ 9041.59/s (n=50000) I think, it is very good results, if I don't work with helpers. But I need to use helpers. Is there any chance to see a fast and nice method to load Reusable Blocks from another template without preliminary rendering in Mojolicious? Reusable template blocks are meant for one template only, for everything > beyond that we have helpers and partial templates. > > -- > sebastian > -- You received this message because you are subscribed to the Google Groups "Mojolicious" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/mojolicious. For more options, visit https://groups.google.com/d/optout.
