Guest User

Untitled

a guest
Aug 17th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. ### ruby 1.8.7 (REE)
  2.  
  3. irb(main):031:0> start = Time.now; 10_000_000.times { 'foo' }; puts Time.now - start
  4. => 2.154165
  5. irb(main):032:0> start = Time.now; 10_000_000.times { "foo" }; puts Time.now - start
  6. => 2.177029
  7.  
  8. Remind me again, why do I care about 23 milliseconds for every 10 million string
  9. loads? Methinks that just one instance of needing to change single quotes to
  10. double quotes so you can do some interpolation that you hadn't originally
  11. foreseen will take more time than a month of ruby loading double quotes, unless
  12. its on some superduper hyper sensitive performance critical inner loop (in which
  13. case, are you sure ruby is the right language for you?). Am I wrong?
  14.  
  15. Oh, and how about other versions of ruby?
  16.  
  17. ### ruby 1.9.3-rc1:
  18. irb(main):002:0> start = Time.now; 10_000_000.times { "foo" }; Time.now - start
  19. => 1.551125075
  20. irb(main):003:0> start = Time.now; 10_000_000.times { 'foo' }; Time.now - start
  21. => 1.535057393
  22.  
  23. Again, why do I care about 16 milliseconds for every 10 million string loads?
  24.  
  25. ### Rubinius 2.0.0-dev:
  26. irb(main):004:0> start = Time.now; 10_000_000.times { 'foo' }; Time.now - start
  27. => 0.745409
  28. irb(main):005:0> start = Time.now; 10_000_000.times { "foo" }; Time.now - start
  29. => 0.807167
  30.  
  31. This is the biggest difference yet. An awe inspiring 55 milliseconds per 10
  32. million string loads. Again, a single instance of changing to double quotes
  33. because of an unforeseen interpolation will erase that entire performance
  34. penalty.
  35.  
  36. ### JRuby 1.6.4:
  37. irb(main):003:0> start = Time.now; 10_000_000.times { "foo" }; Time.now - start
  38. => 0.743
  39. irb(main):004:0> start = Time.now; 10_000_000.times { 'foo' }; Time.now - start
  40. => 0.757
  41.  
  42. Not only is JRuby just plain faster overall, it's *also* faster for double
  43. quotes than single quotes!
  44.  
  45. ### In conclusion
  46.  
  47. These benchmarks are complete BS. If you have profiled actual production code
  48. and see a significant speedup in a performance critical section, then go ahead
  49. and make the change.
  50.  
  51. But I like my default design choices to be *useful*. I like to optimize for the
  52. programmers first and the computer second.
  53.  
  54. Anyway, if you *really* care about pre-optimizing microseconds: use double quotes by
  55. default and switch to JRuby.
Add Comment
Please, Sign In to add comment