Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (495)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Which codes are more efficient?  (Read 1924 times)
0 Members and 1 Guest are viewing this topic.
Offline perfectlifepan

Senior Newbie




Java games rock!


« Posted 2005-04-12 04:15:23 »

1a) for(int i=0;i<100;i++){
     if(a == 0 && a==1)//a is int
     System.out.println("abc");
   }
 b) for(int i=0;i<100;i++){
      if(a != 0 || a!=1)continue;
      System.out.println("abc");
     }

2a) for(int i=0;i<100;i++){
     System.out.println (this.getObject1().getObject2().getText());
   }
 b)
     Object2 o2 = this.getObject1().getObject2();
     for(int i=0;i<100;i++){
      System.out.println(o2.getText());
     }

3a) for(int i=0;i<100;i++){
     if(str.equal("1"))
     System.out.println("str");
   }
 b) for(int i=0;i<100;i++){
      if(Integer.parseInt(str) == 1)
      System.out.println("str");
     }
 c) for(int i=0;i<100;i++){
      if(str.charAt(0) == '1')
      System.out.println("str");
     }

Offline oNyx

JGO Coder


Medals: 2


pixels! :x


« Reply #1 - Posted 2005-04-12 04:58:38 »

a) use a profiler
b) all of those versions are about equally slow/fast... the most time is spend in the print method

弾幕 ☆ @mahonnaiseblog
Offline Linuxhippy

Senior Member


Medals: 1


Java games rock!


« Reply #2 - Posted 2005-04-12 06:55:40 »

to be honest ... if you're lonely try to find someone in a chatroom...
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Vorax

Senior Member


Projects: 1


System shutting down in 5..4..3...


« Reply #3 - Posted 2005-04-12 09:05:57 »

There is an answer for each, but it looks to much like some kind of homework for me to give em.

Offline princec

JGO Kernel


Medals: 378
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #4 - Posted 2005-04-12 11:07:55 »

Quote
to be honest ... if you're lonely try to find someone in a chatroom...

Or, er, get out more and try to meet some girls Wink

Cas Smiley

Offline blahblahblahh

JGO Coder


Medals: 1


http://t-machine.org


« Reply #5 - Posted 2005-04-12 11:34:31 »

Quote
1a)
     if(a == 0 && a==1)


Interesting...

ANywy, the answer is "they're all the same" except one.

malloc will be first against the wall when the revolution comes...
Offline Markus_Persson

JGO Wizard


Medals: 15
Projects: 19


Mojang Specifications


« Reply #6 - Posted 2005-04-12 12:16:38 »

That CAN return true with some tricky threading and some luck. Grin

Play Minecraft!
Offline Abuse

JGO Knight


Medals: 12


falling into the abyss of reality


« Reply #7 - Posted 2005-04-12 13:11:20 »

1 will be fastest, if a is null Smiley

Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here! https://dl.dropbox.com/u/54785909/EliteIVsmaller.png
Offline blahblahblahh

JGO Coder


Medals: 1


http://t-machine.org


« Reply #8 - Posted 2005-04-12 13:15:23 »

Quote
That CAN return true with some tricky threading and some luck. Grin


Dang. Fair enough Smiley

When replying, I momentarily wonderd if the compiler would compile it out, and then remembered:

1  
2  
3  
4  
5  
void blah() throws Exception
{
throw new Exception();
String a = "poor little me";
}


...does not compile, but:

1  
2  
3  
4  
5  
6  
void blah() throws Exception
{
if( true )
  throw new Exception();
String a = "poor little me";
}


does. And so does:


1  
2  
3  
4  
5  
6  
void blah() throws Exception
{
if( 1 == 1 )
   throw new Exception();
String a = "poor little me";
}


...so, hotspot might compile it out, but it's far from assured Wink.

malloc will be first against the wall when the revolution comes...
Offline mikelomax

Senior Newbie




I know exactly what i'm doing... asking for help


« Reply #9 - Posted 2005-04-15 09:20:32 »

Depends what he means by efficient and what the job is that you want it to do as if it doesn't do the right job, it isn't that efficient.

The reason for having: A firewall

Independance day, the aliens were destroyed because a computer was used to access their network and disable key systems. If they had had a firewall, the earth would be another worthless rock just floating in space
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Dwinin (25 views)
2014-09-12 09:08:26

Norakomi (56 views)
2014-09-10 13:57:51

TehJavaDev (69 views)
2014-09-10 06:39:09

Tekkerue (35 views)
2014-09-09 02:24:56

mitcheeb (56 views)
2014-09-08 06:06:29

BurntPizza (40 views)
2014-09-07 01:13:42

Longarmx (26 views)
2014-09-07 01:12:14

Longarmx (33 views)
2014-09-07 01:11:22

Longarmx (31 views)
2014-09-07 01:10:19

mitcheeb (39 views)
2014-09-04 23:08:59
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!