Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Which loop is faster?

Name: Anonymous 2012-01-16 8:59


for (I = 0; I < N; I++)
  for (J = 0; J < M; J++)
    update(Xs[I][J]);

or

for (I = 0; I < N; I++)
  for (J = 0; J < M; J++)
    update(Xs[J][I]);

???

Name: Anonymous 2012-01-16 13:25

Aspies fucking TOLD.

http://java.sun.com/docs/books/jls/third_edition/html/expressions.html#15.17.3

Remainder operator

In computing, the modulo operation finds the remainder of division of one number by another.

Name: Anonymous 2012-01-16 13:26

Guys
http://java.sun.com/docs/books/jls/third_edition/html/expressions.html#15.17.3
it's the remainder operator,
What we understand by modulo division.

Name: Anonymous 2012-01-16 13:27

The binary % operator is said to yield the remainder of its operands from an implied division; the left-hand operand is the dividend and the right-hand operand is the divisor.

Name: kodak_gallery_programmer !!kCq+A64Losi56ze 2012-01-16 13:27

And this is why I work as a programmer for a living -).

Name: Anonymous 2012-01-16 13:28

Java
And this thread went quickly to shit. Just like GC.

Name: Anonymous 2012-01-16 13:29

Name: Anonymous 2012-01-16 13:29

>>84
How does failing to understand that the remainder operation is same as modulo division help?

Name: Anonymous 2012-01-16 13:30

>>84
And this is why I work as a programmer for a living
Confirmed for Java code monkey. Enjoying being a toilet scrubber?

Name: Anonymous 2012-01-16 13:31

>>87
Uhh... because one is divisible by zero and the other isn't?

Name: Anonymous 2012-01-16 13:32

>>88
You're just mad because you screwed the pooch.

Name: Anonymous 2012-01-16 13:37

>>89
No

Name: kodak_gallery_programmer !!kCq+A64Losi56ze 2012-01-16 13:39

>>87
Look at the examples given in the document.

Name: Anonymous 2012-01-16 13:39

>>89
Uhh... because one is divisible by zero and the other isn't?
Nope. Neither is divisible by zero.

$ cat test.java

class test {
    public static void main(String[] args) {
        int herp = 3, derp = 0;
        System.out.println(herp % derp);
    }
}

$ java test
Exception in thread "main" java.lang.ArithmeticException: / by zero
        at test.main(test.java:4)


n mod 1 is always 0; n mod 0 is undefined, possibly resulting in a "Division by zero" error in computer programming languages

Name: Anonymous 2012-01-16 13:41

>>89
No. Just shut up, retard.

Name: Anonymous 2012-01-16 13:42

>>92
What examples? Also >>93

Fucking told.

Name: kodak_gallery_programmer !!kCq+A64Losi56ze 2012-01-16 13:45

>>95
http://java.sun.com/docs/books/jls/third_edition/html/expressions.html#15.17.3

Has the following:

5%3 produces 2                 (note that 5/3 produces 1)
5%(-3) produces 2               (note that 5/(-3) produces -1)
(-5)%3 produces -2              (note that (-5)/3 produces -1)
(-5)%(-3) produces -2           (note that (-5)/(-3) produces 1)

Name: Anonymous 2012-01-16 13:45

>>96
divisible by zero
I see none.

Name: Anonymous 2012-01-16 13:47

>>97
If the dividend is an infinity, or the divisor is a zero, or both, the result is NaN.
It's still not divisble by zero FYI, but atleast defined.

Name: Anonymous 2012-01-16 13:48

>>98
Oh, and NaN just means that it's an undefined number.

Name: kodak_gallery_programmer !!kCq+A64Losi56ze 2012-01-16 13:48

>>97
It was in response to the person who asked

>How does failing to understand that the remainder operation is same as modulo division help?

Name: Anonymous 2012-01-16 13:48

>>98'
>cool story bro

>>93

Name: Anonymous 2012-01-16 13:49

>>99
it's defined, it's undefined
ITT: Autism

Name: Anonymous 2012-01-16 13:51

>>101
the part with 0 is only true for floating point numbers

Name: Anonymous 2012-01-16 13:53

>>100
ffs learn to respond correctly

Name: Anonymous 2012-01-16 13:55

ITT:
it's well-defined, it's defined as undefined

Name: Anonymous 2012-01-16 13:57

>>105
Welcome to /prog/
If this surprises you, you must be new here.
Goodbye and go back to /g/ when it's back up.

Name: Anonymous 2012-01-16 14:00

>>106
I'm still failing to see how division by zero is allowed in Java. All I see is the tripfag (you?) claim it

Name: Anonymous 2012-01-16 14:04

>>106
Actually, we'd all prefer it if you went away and never came back.

Name: kodak_gallery_programmer !!kCq+A64Losi56ze 2012-01-16 14:05

>>107
Geeze, this would be easier if you just wrote some code...

public class Main {

    public static void main(String[] args) {
        int x = 5;
        int y = 0;
        int z = 0;

        try {
            z = x/y;
        } catch (Exception e) {
            System.out.println("Can't divide by zero");
        }
       
    }
}


And the result...

run:
Can't divide by zero
BUILD SUCCESSFUL (total time: 0 seconds)

Name: Anonymous 2012-01-16 14:06

>>109
Can't divide by zero
That's what I said... wat.. No one can really follow your aspie train of thought.

Name: Anonymous 2012-01-16 14:07

>>107
And just in case you have me filtered...

Geeze, this would be easier if you just wrote some code...

public class Main {

    public static void main(String[] args) {
        int x = 5;
        int y = 0;
        int z = 0;

        try {
            z = x/y;
        } catch (Exception e) {
            System.out.println("Can't divide by zero");
        }
       
    }
}


And the result...

run:
Can't divide by zero
BUILD SUCCESSFUL (total time: 0 seconds)

Name: Anonymous 2012-01-16 14:08

>>110
I was clearly responding to the toilet scrubber who asked...

>I'm still failing to see how division by zero is allowed in Java. All I see is the tripfag (you?) claim it

Name: Anonymous 2012-01-16 14:10

>>65
% in Java means something different than % in C and C++.

Name: kodak_gallery_programmer !!kCq+A64Losi56ze 2012-01-16 14:10

The point is that it is possible to divide by zero in java.

Name: Anonymous 2012-01-16 14:10

>>111'
>hurr durr


[code]
#include <stdio.h>
#include <setjmp.h>

jmp_buf p;

void sighdlr() {
    longjmp(p, 1);
}

int main() {
    int a = 3, b = 0, c;
    signal(SIGFPE, sighdlr);
    if (!setjmp(p)) {
        c = a / b;
    } else {
        puts("Can't divide by zero");
    }
    return 0;
}

Name: Anonymous 2012-01-16 14:13

>>114
it is possible to divide by in C in the same matter as in Java,
using IEEE floatint point numbers,
as fact C does not support % operator for FPN Java does.

Name: Anonymous 2012-01-16 14:13

>>114
see >>115

Name: kodak_gallery_programmer !!kCq+A64Losi56ze 2012-01-16 14:16

>>115
Yeah, but doing something like that isn't always reliable. Eer... an actual C implementation that emulates someting like try/catch is long and complicated. Seriously. I've seen several talented programmers fuck it up.

Name: Anonymous 2012-01-16 14:18

>>118
I've seen several talented programmers fuck it up.
Your standards are pretty low.

Name: Anonymous 2012-01-16 14:29

>>1
Assuming this is C or something along those lines, arrays are stored in row-major order. This means that the former accesses elements sequentially with respect to their location in memory, while the latter has doesn't, so there is no sequential locality. This can, and in practice will, impact performance. (The only exception is if update() is inlined and all it does is write to Xs, in which case caching wouldn't be attempted.) I don't think the compiler could make any optimizations, especially with more non-trivial cases.

>>13
What difference does it make whether it's interpreted or compiled?

>>15
That is the reason, actually. Unless the structure, or at least some of the rows, are small enough to fit into a cache line, or if there is no attempt to cache the data (see above), the second example won't benefit from caching.

>>17
Have you ever done anything beyond that :o

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List