• Welcome to Smashboards, the world's largest Super Smash Brothers community! Over 250,000 Smash Bros. fans from around the world have come to discuss these great games in over 19 million posts!

    You are currently viewing our boards as a visitor. Click here to sign up right now and start on your path in the Smash community!

Best programming langugage for my code?

KrazyGlue

Smash Champion
Joined
Feb 23, 2009
Messages
2,302
Location
Northern Virginia
I have a question regarding which language I should be running my code in to make it run faster (it's currently in Java). It's kind of confidential, but I'll explain in basic terms what it does.

It takes an integer input from the user (we'll call it x). It then makes a two-dimensional boolean array with x amount of rows and columns. Each possible combination of trues and falses in the array is then generated, and each time a new combination is generated, the program checks for a certain pattern of trues and falses.

Unfortunately, the code has to check two to the x-squared amount of combinations. For example, if x=5, the code has to check 2^25 combinations, or about 33.5 million. If x=6, it has to check 2^36 combinations, or 6.8 billion. If x=7, it has to check 562 trillion times. I don't want to go into specifics, but it also has to check each combination of the boolean array many different times in order to see if it can find the patterns of trues/falses it is looking for. As you can see, it takes TONS of time.

Thankfully, we only have to check half of those boolean array combinations because the second half of them are just the exact opposite of the first half. We've also multithreaded it to allow the program to use all of the computer's cores (with the discretion of the user). Still, we'd like to make it a lot faster.

Right now the program is in java. A friend of mine recommended using an assembly language. Should I use Java, an assembly language, or something else?

Thanks in advance for your help and sorry in advance for the cryptic OP.
 

Superstar

Smash Champion
Joined
Feb 9, 2007
Messages
2,351
Location
Miami, Florida
DO NOT USE ASSEMBLY. That's the first thing. It won't be worth it.

2nd, what's your CPU? Just curious.

C and C++ are faster than Java, but it seems by the very nature of your program, you're not going to get any quick results. Seems you're better off trying to optimize it than switching the language. What's the point of what you're doing [maybe some slick algorithm can be used], and maybe post your code?
 

KrazyGlue

Smash Champion
Joined
Feb 23, 2009
Messages
2,302
Location
Northern Virginia
DO NOT USE ASSEMBLY. That's the first thing. It won't be worth it.

2nd, what's your CPU? Just curious.

C and C++ are faster than Java, but it seems by the very nature of your program, you're not going to get any quick results. Seems you're better off trying to optimize it than switching the language. What's the point of what you're doing [maybe some slick algorithm can be used], and maybe post your code?
  1. Ok, thank you very much. May I ask why not? Too complex or something? (Just out of curiosity :))
  2. Well, my CPU is old so I'm using my friend's and I don't know about his... I'll try and ask and see if I can get back to you.
  3. Yeah, there's not going to be quick results either way. The point is to solve a famous mathematical problem (don't laugh!! :)) so that's why I'm somewhat reluctant to post my code here (someone else might take it!!!). I figured that telling you the gist of the process is enough to determine what language is best, but if it's not I'll consider posting the code.
 

TheBuzzSaw

Young Link Extraordinaire
Moderator
BRoomer
Joined
Jul 21, 2005
Messages
10,479
Before jumping ship to any other languages, keep in mind that using threads would speed this program up considerably (provided you have at least a dual core processor). Java makes threading easy. Threads would give a much bigger speed boost than merely switching over to C/C++ (unless of course you went hardcore and learned C/C++ threads).

^_^
 

KrazyGlue

Smash Champion
Joined
Feb 23, 2009
Messages
2,302
Location
Northern Virginia
Before jumping ship to any other languages, keep in mind that using threads would speed this program up considerably (provided you have at least a dual core processor). Java makes threading easy. Threads would give a much bigger speed boost than merely switching over to C/C++ (unless of course you went hardcore and learned C/C++ threads).

^_^
Yeah, you're probably right. We did already enable it to use both cores (we're using a dual core processor), unless you mean something else...?
 

Kirby King

Master Lameoid
Premium
BRoomer
Joined
Feb 8, 2002
Messages
7,577
Location
Being a good little conformist
Yeah... you're trying to solve a problem using an exponential-time algorithm. It really doesn't matter what language you use, it's going to be slow no matter what. Superstar's right--try to optimize the algorithm, because if you can't, it really doesn't matter much what else you do.
 

Superstar

Smash Champion
Joined
Feb 9, 2007
Messages
2,351
Location
Miami, Florida
I said not to use assembly because it's really complicated. And programming languages fundamentally convert to Assembly anyways. Trust me on this, I've done assembly [ARM7 though] before. It's a pain.

Oh, you're trying to find one of those "I'll pay you if you get it" problems. I understand why you were vague on the purpose. The problem is though that I can't help you if I can't see the algorithm, so I'll give a few obvious tips:

1) Use bitwise over multiplication and division. Shifting a bit is a lot faster than dividing by 2.
2) Maybe break up certain divisions into two bitwise operations. Depends on it.
3) Recursion is faster than using a while loop, at least I hear.
4) Try to define the problem in some mathematical way in order to vastly reduce the required number of iterations.
5) Maybe fundamentally certain combinations are impossible. It's fine to get hacky for these kinds of problems.

And I asked CPU because it matters, not just clock and cores but clock per clock. If you're using a laptop for this, well, bad. If you can run it on an i7 machine you'll get a lot faster results.

EDIT: Also remember that going between cores is slower than just running seperately on the cores. DO NOT alternate one thread this other thread that, and do not have the threads constantly communicating with each other. Put half of all possible stuff [maybe those starting with true] on one core and all the half on the other. Make the only "link" once the result has been found.

EDIT2: Use larger scope variables than redeclaring each iteration. Internally Java creates pointers and allocations each time you make a variable, so make sure each variable is only created once [assuming Java doesn't optimize it for you].

Code:
//good
int temp = 0;
while(true)
{
    //do stuff with temp
}

//bad
while(true)
{
    int temp = stuff;
}
 

KrazyGlue

Smash Champion
Joined
Feb 23, 2009
Messages
2,302
Location
Northern Virginia
Thank you so much for all of that, Superstar. :)
That is exactly what I had hoped for.

My bad about the CPU, I thought since you said "just curious" that you meant it wasn't really important. I'll get that info as soon as I can.
 

TheBuzzSaw

Young Link Extraordinaire
Moderator
BRoomer
Joined
Jul 21, 2005
Messages
10,479
Yeah, you're probably right. We did already enable it to use both cores (we're using a dual core processor), unless you mean something else...?
What does "enable it to use both cores" mean? Did you use threads?
 

Superstar

Smash Champion
Joined
Feb 9, 2007
Messages
2,351
Location
Miami, Florida
I said "just curious" because no matter what it is you can't change anything (without paying significant money). All I can say is whether or not you'll get the answer with any reasonable speed.

Thought of something else you could do. If you have to constantly check a large sequence of trues and false (less than 64 but say, more than 3 or something), instead of looping through trues and falses and checking each one, it may be faster to assemble the trues as a series of bits, and then just check once.

EX: True true true false true false false false = 11101000.

This may be slower, it probably depends on a lot of things. Maybe do a smaller version and use System.currentTimeMillis() to check how long it took, and compare.

Before doing any optimization I'd actually recommend testing the difference in speed, maybe making the program run for a minute or so. Sometimes Java may optimize it better than you could ever do, that's how compilers usually are.
 

KrazyGlue

Smash Champion
Joined
Feb 23, 2009
Messages
2,302
Location
Northern Virginia
I said "just curious" because no matter what it is you can't change anything (without paying significant money). All I can say is whether or not you'll get the answer with any reasonable speed.

Thought of something else you could do. If you have to constantly check a large sequence of trues and false (less than 64 but say, more than 3 or something), instead of looping through trues and falses and checking each one, it may be faster to assemble the trues as a series of bits, and then just check once.

EX: True true true false true false false false = 11101000.

This may be slower, it probably depends on a lot of things. Maybe do a smaller version and use System.currentTimeMillis() to check how long it took, and compare.

Before doing any optimization I'd actually recommend testing the difference in speed, maybe making the program run for a minute or so. Sometimes Java may optimize it better than you could ever do, that's how compilers usually are.
Ah, good ideas!

As for testing the speed, we have already have a line of code that tells us how many minutes we have left every so often, so that should do the trick.
 
Top Bottom