Hi !
Featured games (84)
games approved by the League of Dukes
Games in Showcase (604)
Games in Android Showcase (171)
games submitted by our members
Games in WIP (654)
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 1999 times)
0 Members and 1 Guest are viewing this topic.
Offline TLE

Senior Newbie

« Posted 2007-06-13 03: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 Devvie

« Reply #1 - Posted 2007-06-13 11: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 12: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 Devvie

Projects: 1
Exp: 15 years

Used to be bleb

« Reply #3 - Posted 2007-06-13 13: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-13 23:22:54 »

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

Junior Devvie

Introducing the world's cutest zombie, Timmy

« Reply #5 - Posted 2007-06-14 02: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 09:23:03 »

so how do you profile your code Smiley
Offline Kova

Senior Devvie

« Reply #7 - Posted 2007-06-14 14: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 15: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 Devvie

« Reply #9 - Posted 2007-06-14 16: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-16 22: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.

bilznatch (20 views)
2015-08-04 11:03:17

SHC (39 views)
2015-08-01 03:58:20

Jesse (24 views)
2015-07-29 04:35:27

Riven (45 views)
2015-07-27 16:38:00

Riven (25 views)
2015-07-27 15:35:20

Riven (27 views)
2015-07-27 12:26:13

Riven (18 views)
2015-07-27 12:23:39

BurntPizza (41 views)
2015-07-25 00:14:37

BurntPizza (50 views)
2015-07-24 22:06:39

BurntPizza (33 views)
2015-07-24 06:06:53
List of Learning Resources
by gouessej
2015-07-09 11:29:36

How Do I Expand My Game?
by bashfrog
2015-06-14 11:34:43

List of Learning Resources
by PocketCrafter7
2015-05-31 05:37:30

Intersection Methods
by Roquen
2015-05-29 08:19:33

List of Learning Resources
by SilverTiger
2015-05-05 10:20:32

How to: JGO Wiki
by Mac70
2015-02-17 20:56:16

2D Dynamic Lighting
by ThePixelPony
2015-01-01 20:25:42

How do I start Java Game Development?
by gouessej
2014-12-27 19:41:21 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‑
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!