performance question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Murat Tasan

    performance question

    how well is javac from sun's jdk tools optimized?

    wow, that's a general question... so i guess here is a simple example...
    let's say i have a program that uses an array.
    and many times in the program i need to do computation that rely on the
    array's length.

    so, how much speedup (if any at all) is there to storing the array length
    as an int and using that in the computations, compared with constantly
    using the arrayName.lengt h method?

    thanks for any insight, or pointing me to some not-too-in-depth
    documentation on the runtime system of java and how optimizations at
    compile time are done.

    thanks again!

    murat

    --
    Murat Tasan
    mxt6@po.cwru.ed u
    tasan@eecs.cwru .edu
    murat.tasan@cwr u.edu
    Learn how the Genomics Core at Case Western Reserve University can provide you with a wide range of genomics and DNA/RNA quality control services.


  • Karl von Laudermann

    #2
    Re: performance question

    Murat Tasan <tasan@eecs.cwr u.edu> wrote in message news:<Pine.SOL. 4.53.0310231524 410.28593@homer >...[color=blue]
    > how well is javac from sun's jdk tools optimized?
    >
    > wow, that's a general question... so i guess here is a simple example...
    > let's say i have a program that uses an array.
    > and many times in the program i need to do computation that rely on the
    > array's length.
    >
    > so, how much speedup (if any at all) is there to storing the array length
    > as an int and using that in the computations, compared with constantly
    > using the arrayName.lengt h method?[/color]

    In this case, you wouldn't see any speed improvement, because length
    isn't a method; it's an instance variable.

    As Donald Knuth wrote, "Premature optimization is the root of all
    evil." You should write your code in the most natural way. Afterwards,
    if you are not satisfied with performance, use a profiler to find out
    where the bottlenecks are and just optimize the parts that need it.

    Comment

    • Amey Samant

      #3
      Re: performance question

      Murat Tasan <tasan@eecs.cwr u.edu> wrote in message news:<Pine.SOL. 4.53.0310231524 410.28593@homer >...
      [color=blue]
      > let's say i have a program that uses an array.
      > and many times in the program i need to do computation that rely on the
      > array's length.
      >
      > so, how much speedup (if any at all) is there to storing the array length
      > as an int and using that in the computations, compared with constantly
      > using the arrayName.lengt h method?
      > murat[/color]

      hi
      in your example, your method has following disadvantages
      1) you must update length variable as and when array is allocated new
      elements
      for eg
      if in your prog you have something like arr=new int[5]; then you must
      update length variable maintained by you.
      2) its a duplicate variable ... i mean arr.length is a variable & not
      a method, so why you want to maintain a copy of original variable
      3) if you have 10 arrays , do you want to allocate 10 variables for
      maintaining array size when its already taken care of ....
      or would you go for havin an array of size 10 say lengths[10] ;) &
      then maintain size of this array in seperate variable ;)

      hope i made it clear
      regards
      amey

      Comment

      • Phil...

        #4
        Re: performance question

        compared to what? GCC? not very

        "Murat Tasan" <tasan@eecs.cwr u.edu> wrote in message
        news:Pine.SOL.4 .53.03102315244 10.28593@homer. ..[color=blue]
        > how well is javac from sun's jdk tools optimized?
        >
        > wow, that's a general question... so i guess here is a simple example...
        > let's say i have a program that uses an array.
        > and many times in the program i need to do computation that rely on the
        > array's length.
        >
        > so, how much speedup (if any at all) is there to storing the array length
        > as an int and using that in the computations, compared with constantly
        > using the arrayName.lengt h method?
        >
        > thanks for any insight, or pointing me to some not-too-in-depth
        > documentation on the runtime system of java and how optimizations at
        > compile time are done.
        >
        > thanks again!
        >
        > murat
        >
        > --
        > Murat Tasan
        > mxt6@po.cwru.ed u
        > tasan@eecs.cwru .edu
        > murat.tasan@cwr u.edu
        > http://genomics.cwru.edu
        >[/color]


        Comment

        • John

          #5
          Re: performance question


          "Karl von Laudermann" <karl@ueidaq.co m> wrote in message
          news:e7e6125e.0 310240548.1df39 070@posting.goo gle.com...[color=blue]
          > Murat Tasan <tasan@eecs.cwr u.edu> wrote in message[/color]
          news:<Pine.SOL. 4.53.0310231524 410.28593@homer >...[color=blue][color=green]
          > > how well is javac from sun's jdk tools optimized?
          > >
          > > wow, that's a general question... so i guess here is a simple example...
          > > let's say i have a program that uses an array.
          > > and many times in the program i need to do computation that rely on the
          > > array's length.
          > >
          > > so, how much speedup (if any at all) is there to storing the array[/color][/color]
          length[color=blue][color=green]
          > > as an int and using that in the computations, compared with constantly
          > > using the arrayName.lengt h method?[/color]
          >
          > In this case, you wouldn't see any speed improvement, because length
          > isn't a method; it's an instance variable.
          >
          > As Donald Knuth wrote, "Premature optimization is the root of all
          > evil." You should write your code in the most natural way. Afterwards,
          > if you are not satisfied with performance, use a profiler to find out
          > where the bottlenecks are and just optimize the parts that need it.[/color]

          It is amazing how much work modern compilers do in optimisation. Even if you
          did make a method call at each loop, it would cost you bugger all in running
          time. The compiler will even clear up programmer stupidity, such as creating
          variables that aren't used. I'd have to look up the specifics of javac to
          tell you exactly what it does though. My favourite optimisation task (after
          manual profiling) is simplifying, sorting and predicting the size of data
          structures, which can make significant savings in complexity. I agree with
          the post above (and Knuth), but with the preserve that it is not a license
          for lazy design programming (always using (ie) util.Vector and never
          bothering to sort anything).

          John


          Comment

          Working...