• Login
sketchucation logo sketchucation
  • Login
🤑 SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

Integer vs string test time

Scheduled Pinned Locked Moved Developers' Forum
3 Posts 2 Posters 196 Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    honoluludesktop
    last edited by 31 Mar 2011, 17:39

    I understand that if vari=="0" is slower then if vari==0. Is it better to do if vari.to_i==0?

    1 Reply Last reply Reply Quote 0
    • C Offline
      Cleverbeans
      last edited by 31 Mar 2011, 17:48

      It seems to be slower to do the conversion then do the comparison. To test something like this you can use the Time.now() method to make a simple stopwatch. Here is how I tested it.

      
      def str_test()
         t = Time.now()
         (1..10000000).each{|i| "0" == "0"}
         puts(Time.now() - t)
      end
      
      def int_test()
         t = Time.now()
         (1..10000000).each{|i| "0".to_i == 0}
         puts(Time.now() - t)
      end
      
      

      str_test ran in 6.922 and int_test ran in 8.406, feel free to run the test yourself.

      1 Reply Last reply Reply Quote 0
      • H Offline
        honoluludesktop
        last edited by 31 Mar 2011, 18:02

        Thanks, I will have to remember how to do that:)

        1 Reply Last reply Reply Quote 0
        • 1 / 1
        1 / 1
        • First post
          1/3
          Last post
        Buy SketchPlus
        Buy SUbD
        Buy WrapR
        Buy eBook
        Buy Modelur
        Buy Vertex Tools
        Buy SketchCuisine
        Buy FormFonts

        Advertisement