Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (577)
games submitted by our members
Games in WIP (498)
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  
  Trade off question  (Read 1639 times)
0 Members and 1 Guest are viewing this topic.
Offline TLE

Senior Newbie





« Posted 2007-06-13 05:39:24 »

I'm writing some code that uses a triplet of integers which new integers are created fairly often.  Currently I have them written as a class with 3 elements.  This makes it really easy to use and easier to understand.  However, I don't know what the creation of this small class actually encumbers, and I don't know how much extra garbage collection it creates.  So I've come up with a clever alternative, where instead of using a class, I just use a single integer.  I know each of the 3 ints will be small ranges, and will fit in 2 digits, so I figured I could use a 6 digit number and use divisions to separate them.  This code seems like it would take less memory and time to implement, though it's much harder to understand -- should I not look at it for 6 months, I might not remember what the hell I was doing.  Of course I can always comment away and hope it's understandable later.  So, if these triplets are created often enough, is it really worth it to make the code a little more complicated?
Offline purpleguitar

Junior Member





« Reply #1 - Posted 2007-06-13 13:09:45 »

Premature optimization is the root of all evil.

First get your program to work.  Then you can look for performance bottlenecks.  It is better to have a clear design than a "clever" one.
Offline TLE

Senior Newbie





« Reply #2 - Posted 2007-06-13 14:58:16 »

Yea, it's already working, that's why I'm looking into optimizing it.  But I don't know how java implements these things, so I need some input from others.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ryanm

Senior Member


Projects: 1


Used to be bleb


« Reply #3 - Posted 2007-06-13 15:29:57 »

Have you profiled your code? Do you know for a fact that optimising this bit is worthwhile?
Offline TLE

Senior Newbie





« Reply #4 - Posted 2007-06-14 01:22:54 »

No I don't know, that's the whole point of my question :\
Offline Coinerson

Junior Member




Introducing the world's cutest zombie, Timmy


« Reply #5 - Posted 2007-06-14 04:15:28 »

No I don't know, that's the whole point of my question :\

Noone can tell you if your code is fast or not if you don't profile it. Doesn't sound like it matters at all though.
Offline ravenger

Senior Newbie





« Reply #6 - Posted 2007-06-14 11:23:03 »

so how do you profile your code Smiley
Offline Kova

Senior Member





« Reply #7 - Posted 2007-06-14 16:52:33 »

determine what is slowest machine you want your game to be able to run on, find that machine and try to run it Smiley
if your game is too slow, profile it with some profiler, netbeans profiler is said to be the best.
Offline TLE

Senior Newbie





« Reply #8 - Posted 2007-06-14 17:47:34 »

Ok, I think I'll just leave it how it is.  Really was trying to figure out if constantly creating this class of 3 ints was creating a lot of extra overhead, but since nobody jumped out and said "holy crap that's the most inefficient thing I've ever heard!", I imagine it's not going to cause a problem.  Thanks.
Offline Kova

Senior Member





« Reply #9 - Posted 2007-06-14 18:23:43 »

oh yeah, it may not be slow, but why are you constantly creating that class? Couldn't you create it once and then reuse it instead of creating another?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline TLE

Senior Newbie





« Reply #10 - Posted 2007-06-17 00:53:04 »

Wow, can't believe I hadn't even thought of that, it's so simple!  I'll have to change a couple small things to ensure they don't overlap, but that's definitely a huge improvement, thanks kova!
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.

xsi3rr4x (18 views)
2014-04-15 18:08:23

BurntPizza (15 views)
2014-04-15 03:46:01

UprightPath (28 views)
2014-04-14 17:39:50

UprightPath (13 views)
2014-04-14 17:35:47

Porlus (29 views)
2014-04-14 15:48:38

tom_mai78101 (54 views)
2014-04-10 04:04:31

BurntPizza (111 views)
2014-04-08 23:06:04

tom_mai78101 (212 views)
2014-04-05 13:34:39

trollwarrior1 (181 views)
2014-04-04 12:06:45

CJLetsGame (187 views)
2014-04-01 02:16:10
List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:05:20
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!