René Kanters wrote:

> Interesting question.
>
> I would think that the compiler may not be able to optimize that since 
> if any function is called it may modify the JpegObj.VsampFactor[comp] 
> value (possibly as a side-effect only) in which case the loop should 
> have a different high end cutoff.
>
> I wonder whether it may be better to count down in stead, which I 
> vaguely recall Miguel once suggested in an email on Java coding styles.
>
I've started to use the count-down quite a bit:

          for(i = JpegObj.VsampFactor[comp]; --i >=0;) {
            for(j =JpegObj.HsampFactor[comp];--j >=0) {

Very compact.

on something like this, which might go a million times, it seems to me 
worth it to optimize a bit.

Bob



> René
>
> On May 14, 2007, at 5:38 PM, Bob Hanson wrote:
>
>> Java question: Does the following:
>>
>>           for(i = 0; i < JpegObj.VsampFactor[comp]; i++) {
>>             for(j = 0; j < JpegObj.HsampFactor[comp]; j++) {
>>
>>
>> benefit at all in performance with:
>>
>>           int vsf = JpegObj.VsampFactor[comp];
>>           int hsf = JpegObj.HsampFactor[comp];
>>           for(i = 0; i < vsf; i++) {
>>             for(j = 0; j < hsf; j++) {
>>
>>
>> Or does the Java compiler figure out that JpegObj.VsampFactor[comp] is 
>> not changing during the loop and so only assigns it once?
>>
>>
>> Bob
>
>
>------------------------------------------------------------------------
>
>-------------------------------------------------------------------------
>This SF.net email is sponsored by DB2 Express
>Download DB2 Express C - the FREE version of DB2 express and take
>control of your XML. No limits. Just data. Click to get it now.
>http://sourceforge.net/powerbar/db2/
>
>------------------------------------------------------------------------
>
>_______________________________________________
>Jmol-developers mailing list
>[email protected]
>https://lists.sourceforge.net/lists/listinfo/jmol-developers
>  
>


-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Jmol-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jmol-developers

Reply via email to