Is there a performance gain in using single quotes vs double quotes in ruby?

前端 未结 14 677
挽巷
挽巷 2020-11-27 10:32

Do you know if using double quotes instead of single quotes in ruby decreases performance in any meaningful way in ruby 1.8 and 1.9.

so if I type

qu         


        
14条回答
  •  Happy的楠姐
    2020-11-27 10:57

    It's certainly possible depending on the implementation, but the scanning portion of the interpreter should only look at each character once. It will need just an additional state (or possible set of states) and transitions to handle #{} blocks.

    In a table based scanner thats going to be a single lookup to determine transition, and will be happening for each character anyways.

    When the parser gets the scanner output, it's already known that it will have to eval code in the block. So the overhead is only really the memory overhead in the scanner/parser to handle the #{} block, which you pay for either way.

    Unless I'm missing something (or misremembering compiler construction details), which is also certainly possible :)

提交回复
热议问题