Time Cost Comparison: Haml render_to_string vs. string addition
I'm working on something that will render a small bit of xml (10 lines) every second.
I like the ease of constructing Xml with H开发者_运维技巧aml, but I was wondering if anyone knew any details about the server cost of using render_to_string with haml versus building a string with String addition.
Haml is meant to be used when
- you want to generate pretty XML,
- the structure of the XML is hand-edited.
If you are generating small XML documents for machine consumption use faster libraries like Nokogiri or Builder.
Please do not use string interpolation, most of the time you will end up creating malformed documents because the input data will be slightly different from the data you used to test your app. This is true whenever you handle user-generated data. String interpolation is also a nice way to introduce security bugs. Just don't do it.
精彩评论