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 1057327
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T17:51:03+00:00 2026-05-16T17:51:03+00:00

An algorithm written in Java should be faster than the same algorithm written in

  • 0

An algorithm written in Java should be faster than the same algorithm written in JRuby, right?.

However, if I write the algorithm in Java and then call it from JRuby, will I still get the performance advantages of java?

I ask this because I am writing a very complicated utility class for my JRuby on Rails app and need to choose whether to do it in Java or JRuby.

So, if I use the following code:

class UtilitySampleWrapper
  include Java
  require 'utility.jar' #could also use .js class files if that makes a difference

  def initialize
    @p = Utility.new #this is the java utility class
  end

end

Will any code run in the @p object of Utility class be run in pure java and have all of the speed advantages that implies?

if I call

@p.iterate(50)

will the iterate function of the Utility class run in pure Java and then return its result to my JRuby code?

Thanks!

  • 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-16T17:51:04+00:00Added an answer on May 16, 2026 at 5:51 pm

    An algorithm written in Java should be faster than the same algorithm written in JRuby, right?.

    It depends on how well you write the Java version. It is also theoretically possible that for certain algorithms the JRuby compiler can emit bytecodes that run faster than the Java compiler would emit for a functionally equivalent Java program.

    But generally I would expect a hand-optimized Java algorithm to run faster than a hand-optimized JRuby algorithm because of:

    • relative maturity of the Java and JRuby bytecode compilers,
    • the JIT compiler being tuned to optimize bytecodes typical of Java programs, and
    • the JVM bytecode architecture being better suited for Java.

    I don’t know how significant the difference is though. And obviously it would depend on the skills of the person / people doing the hand optimization.

    However, if I write the algorithm in Java and then call it from JRuby, will I still get the performance advantages of java?

    Probably yes, but there are some possible reasons why this might not be the case:

    • You might need to convert between equivalent Java and Ruby classes / types at the call boundary, and the cost of the conversions may negate the benefits of recoding in Java.
    • The real performance bottleneck may not be in this algorithm at all.

    Before you embark on this exercise of recoding JRuby code in Java, you should do some tests to see if this is a worthwhile exercise at all; e.g. does the application already run fast enough? Then you should profile the application to see if the application is really spending all of its time in the algorithm. Finally, you should see if you can optimize the algorithm in JRuby. (For instance if you can replace an O(N**2) JRuby algorithm with an O(N) JRuby algorithm, then that’s better than recoding the original algorithm in Java.)

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

Sidebar

Related Questions

here is full code from algorithm and data structure in java written in c++
I have an algorithm written in Java that I would like to make more
I am currently working on reimplementing some algorithm written in Java in Python. One
I have written a util class in Java for webservice call. My util class
I am trying to profile a ann algorithm written in Java that is implemented
I have a function in java which is written with a recursive algorithm that
I am trying to make equivalence tests on an algorithm written in C++ and
I written an algorithm to calculate the next lexicographic permutation of an array of
I have written an algorithm that takes geospatial data and performs a number of
I've written an algorithm which calculates and stores all paths of a DAG, and

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.