Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6877823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:38:50+00:00 2026-05-27T04:38:50+00:00

Attempting to profile the difference in runtime between 1+1 and 1×2 using Ruby and

  • 0

Attempting to profile the difference in runtime between “1+1” and “1×2” using Ruby and the gem ruby-prof.

Install the gem and hacked together some code that appears to work, but does not give me the answer I’m looking for, that being the difference in runtime.

Is this possible, and if so, what code would give me this answer.


This code appears to work, but does not allow me to see a runtime difference.


require 'ruby-prof'

result = RubyProf.profile do
1+1
end
printer = RubyProf::GraphPrinter.new(result)

result = RubyProf.profile do
1x2
end
printer = RubyProf::GraphPrinter.new(result)

Which returns this in IRB


irb(main):001:0> require 'ruby-prof'
=> true
irb(main):002:0>
irb(main):003:0* result = RubyProf.profile do
irb(main):004:1* 1+1
irb(main):005:1> end
=> #<RubyProf::Result:0x11050c8>
irb(main):006:0> printer = RubyProf::GraphPrinter.new(result)
=> #<RubyProf::GraphPrinter:0x1332c18 @result=#<RubyProf::Result:0x11050c8>, @ou
tput=nil, @options={}, @thread_times={6793716=>0.01}>
irb(main):007:0>
irb(main):008:0* result = RubyProf.profile do
irb(main):009:1* 1x2
irb(main):010:1> end
SyntaxError: (irb):9: syntax error, unexpected tIDENTIFIER, expecting keyword_en
d
        from C:/Ruby193/bin/irb:12:in `<main>'
irb(main):011:0> printer = RubyProf::GraphPrinter.new(result)
=> #<RubyProf::GraphPrinter:0x1124310 @result=#<RubyProf::Result:0x11050c8>, @ou
tput=nil, @options={}, @thread_times={6793716=>0.01}>
irb(main):012:0>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T04:38:51+00:00Added an answer on May 27, 2026 at 4:38 am

    1x2 means nothing in ruby. Use 1*2 instead.

    EDIT: You must run the code more times as it is too fast to measure.

    require 'ruby-prof'
    
    prof1 = RubyProf.profile do
      10_000_000.times {1+1}
    end
    
    prof2 = RubyProf.profile do
      10_000_000.times {1*2}
    end
    
    RubyProf::GraphPrinter.new(prof1).print
    RubyProf::GraphPrinter.new(prof2).print
    

    Anyway I think the best way to do it is with Benchmark:

    require 'benchmark'
    
    Benchmark.bm do |x|
      x.report("1+1") {15_000_000.times {1+1}}
      x.report("1*2") {15_000_000.times {1*2}}
    end
    

    It gives me:

             user     system      total        real
    1+1  2.386000   0.000000   2.386000 (  2.392529)
    1*2  2.403000   0.000000   2.403000 (  2.413323)
    

    Multiplication is just a bit slower. But the difference is too small to mean anything.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am attempting to profile a long running python script. The script does some
I'm attempting to extend django's contrib.auth User model, using an inline 'Profile' model to
I'm attempting to profile junit tests in eclipse on OSX using TPTP . I
I'm attempting to update my profile's settings using checkboxes in a settings page. Once
I am attempting to set a revprop using svnadmin setrevprop /path/to/repos propname propfile -r
I'm attempting to write a browser game using Django but I'm getting a bit
I'm attempting to profile a Java EE project (EJBs, Servlet, JSP) which is deployed
I am attempting to profile a VB6 application. Basically I wanted to work out
I am attempting to dynamically create a profile page. Everything works fine except when
While attempting to access a test portal, I'm encountering the following problem while using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.