which is faster

which is faster to read through, operate on the contents, and replace (see code)? in other words, is there overhead in having an array of myClass with fields vs multiple separate arrays?

MyClass{

publicint i;

publicchar c;

public String s;

}

MyClass[] a;

...

for(int i=0;i<100;i++){

update(a[i].i);

update(a[i].c);

update(a[i].s);

}

or

char[] c;

int[] i;

String[] s;

...

for(int j=0;j<100;j++){

update(i[j]);

update(c[j]);

update(s[j]);

}

[1113 byte] By [00se7ena] at [2007-11-27 10:27:10]
# 1

Do NOT make a decision like that for performance reasons. Performance differences will almost certainly be negligible here, and you shouldn't krap up your code for hypothetical fraction of a percent gain.

If you need the speed of vector processing, use hardware and a language geared toward it. If you're using an OO language, and if i, c, and s are related as attributes of a logical entity in your problem domain, then define a class that encapsulates them.

jverda at 2007-7-28 17:43:53 > top of Java-index,Java Essentials,Java Programming...
# 2

in my mind, the question is, which is harder to debug? Most of the time this stuff isn't all that time critical. If it is, it's not hard to do a little test of your own using timer and running through your competing routines 1000 times or so.

But most importantly, if the data is logically tied together, then it should be programmatically tied together in a class. Otherwise you will be committing yourself to debug-hll.

addendum: Dang, I'm slow!

Message was edited by:

petes1234

petes1234a at 2007-7-28 17:43:53 > top of Java-index,Java Essentials,Java Programming...
# 3

it does make sense to me to put them in a class together because they are related. i think i will just try it in java and then maybe another language like c and see which is faster. what are the fastest languages for vector processing?

00se7ena at 2007-7-28 17:43:53 > top of Java-index,Java Essentials,Java Programming...
# 4

> it does make sense to me to put them in a class

> together because they are related. i think i will

> just try it in java and then maybe another language

> like c and see which is faster. what are the fastest

> languages for vector processing?

I highly, highly doubt that it matters for you right now.

jverda at 2007-7-28 17:43:53 > top of Java-index,Java Essentials,Java Programming...
# 5

> it does make sense to me to put them in a class

> together because they are related.

Then you have a lot to learn about OOP.

> i think i will

> just try it in java and then maybe another language

> like c and see which is faster. what are the fastest

> languages for vector processing?

If you are looking for pure speed at the expense of everything else, then java is probably not for you. You probably need c / c++ / assembly or some other language that is closer to the metal than java.

If you are looking for a language that will allow you to develop stable apps that have a greater degree of re-use and greater ease of debugging, then OOP and java are right up your alley. There is no right or wrong here. It's all totally up to you.

petes1234a at 2007-7-28 17:43:53 > top of Java-index,Java Essentials,Java Programming...
# 6

well i'm highly, highly curious or i wouldn't have asked and since that is the topic i thought someone might know.

00se7ena at 2007-7-28 17:43:53 > top of Java-index,Java Essentials,Java Programming...
# 7

in the example you posted, I feel that the time difference is too small to matter.

petes1234a at 2007-7-28 17:43:53 > top of Java-index,Java Essentials,Java Programming...
# 8

Well then, when you get your hands on a Java compiler and a suitable data set then why don't you try it? But don't bother posting your results here. At least not for me, I'm with the others who say it's a bad question.

DrClapa at 2007-7-28 17:43:53 > top of Java-index,Java Essentials,Java Programming...
# 9

well this forum is clearly a waste of my time. how hard is it to take a question at face value and answer it. maybe i<690789095. i didnt ask you for your opinion of my question but glancing through the other topics around here i can see that most posts get replies that start by criticizing the questioner.

00se7ena at 2007-7-28 17:43:53 > top of Java-index,Java Essentials,Java Programming...
# 10

> well i'm highly, highly curious or i wouldn't have

> asked and since that is the topic i thought someone

> might know.

Most wouldn't know because

1) Most wouldn't have a reason to care.

2) Neither one is likely to be across-the-board faster.

If you're that curious, write tests to find out firsthand.

jverda at 2007-7-28 17:43:53 > top of Java-index,Java Essentials,Java Programming...
# 11

> well this forum is clearly a waste of my time. how

> hard is it to take a question at face value and

> answer it. maybe i<690789095. i didnt ask you for

> your opinion of my question but glancing through the

> other topics around here i can see that most posts

> get replies that start by criticizing the questioner.

Getting awfully thin-skinned are we? Yeah, then I agree. this forum is probably a waste of your time.

petes1234a at 2007-7-28 17:43:53 > top of Java-index,Java Essentials,Java Programming...
# 12

> well this forum is clearly a waste of my time. how

> hard is it to take a question at face value and

> answer it.

If you're so curious, how hard is it for you to test it for yourself? If you can't do that, it can't have any practical significance to you.

> i didnt ask you for

> your opinion of my question

Then hire a yes-man. Don't post on a public, unmoderated forum.

> but glancing through the

> other topics around here i can see that most posts

> get replies that start by criticizing the questioner.

Only those where the question is stupid or poorly phrased and needs clarification. It's not our fault if the number of stupid lazy people is vast.

jverda at 2007-7-28 17:43:53 > top of Java-index,Java Essentials,Java Programming...
# 13

It wasn't just your particular question. Almost every question of the form "Which is faster" can only be answered by "Try it and see". You can't tell how fast code will run just by looking at it, especially now that we have run-time code optimizers. However I will say that your particular question deserved to be criticized on the grounds of poor OO taste. You're free to ignore that, of course, but the basic answer still applies.

DrClapa at 2007-7-28 17:43:53 > top of Java-index,Java Essentials,Java Programming...
# 14

> well this forum is clearly a waste of my time.

And answering a question that you could have answered yourself with some simple test code is a waste of everyone else's time.

jverda at 2007-7-28 17:43:53 > top of Java-index,Java Essentials,Java Programming...
# 15

> it does make sense to me to put them in a class

> together because they are related. i think i will

> just try it in java and then maybe another language

> like c and see which is faster. what are the fastest

> languages for vector processing?

FORTRAN 77.

%

duffymoa at 2007-7-28 17:43:58 > top of Java-index,Java Essentials,Java Programming...
# 16

"Object-Oriented technology is most suited for large "systems" projects implemented by teams of programmers. But Smalltalk, C++ and Java are lousy as Array-Processing Languages. If your objective is to build systems (especially computer systems) or GUI applications, then an Array Processing Language is probably not the best choice. "

http://www.benbest.com/computer/oopapl.html

in case anyone wants to learn something useful about array processing from this thread (i hope its not too late after those dudes rode through on their high horses but really had little to say), i've been doing some googling and found that statement to summarize pretty well.

00se7ena at 2007-7-28 17:43:58 > top of Java-index,Java Essentials,Java Programming...
# 17

So who is Ben Best? and how old is the article? and why is his opinion more valuable than the benchmarking you've been advised to do? and are you really prepared to go and write your array processing in APL?

ejpa at 2007-7-28 17:43:58 > top of Java-index,Java Essentials,Java Programming...
# 18

And if your goal is nothing more thatn array-processing then you may be limiting the scope of your search. For completely optimized array processing you probably have to use a hardware route rather than a software route. There are some types of systems that are built from the IC on up to do optimized array-processing, and to do it well. A useful article can be found here:

http://en.wikipedia.org/wiki/Vector_processor

[soapbox]

And on another note: who is up on their high horse here? If we're quantifying things here, let's quantify everything including the amount of "attitude" contained in the responses. In my estimation, the OP wins hands down. Shall we put this to a vote?

[/soapbox]

petes1234a at 2007-7-28 17:43:58 > top of Java-index,Java Essentials,Java Programming...
# 19

> (i hope its not too

> late after those dudes rode through on their high

> horses but really had little to say),

You must've been reading a different thread than I. That certainly didn't happen here. Of course, if you're one of those that takes offense and any answer that tells you something you didn't want to hear, regardless of the merit of the message, then I could see why you'd have that silly misconception.

> i've been doing

> some googling

Good for you! Seriously.

jverda at 2007-7-28 17:43:58 > top of Java-index,Java Essentials,Java Programming...
# 20

> in case anyone wants to learn something useful about

> array processing from this thread (i hope its not too

> late after those dudes rode through on their high

> horses but really had little to say), i've been doing

> some googling and found that statement to summarize

> pretty well.

It does not summarize correctly though.

There are many factors to consider which you are not doing. The size and overall complexity of the application (and ability to modify and maintain said application) are one thing. Obviously not important to you at this stage but a factor nonetheless.

There is also a factor of runtime optimization which essentially means this. Yes one can certainly write smaller benchmark cases in which C will outperform Java significantly. However, given larger sets of data and operations the performance difference, far from growing will actually diminish. C's performance scalability is going to be linear. Java's perfomance actually improves with larger scales. This is what the benefit of runtime optimization is.

This is actually very important for your question because as hardware grow increasingly smarter and more complex (for example features like multiple cores and hyperthreading) Java will outperform C applications on this hardware. Why? Because the C program will not be taking advantage of these features (unless it is re-written to do so) whereas Java will be able to take whatever advantages of tha hardware that can be obtained because again this is done at runtime and not compile time.

This is why Java's performance in the past may have been an issue in some cases but is (a) not an issue now and (b) is actually a generational improvement over languages like C when it comes to harnessing the full performance potential of current systems and those to come. For proof of this from a non Java source look no further then Microsoft and specifically the .NET and CLR platforms.

Runtime optimization is the tool of tomorrow available today. And that is why your straight comparison question is not a good one. You are comparing apples to oranges and not considering these other factors.

cotton.ma at 2007-7-28 17:43:58 > top of Java-index,Java Essentials,Java Programming...
# 21

> Runtime optimization is the tool of tomorrow

> available today. And that is why your straight

> comparison question is not a good one.

Well, it's *one* reason why... :-)

jverda at 2007-7-28 17:43:58 > top of Java-index,Java Essentials,Java Programming...