/    Sign up×
Community /Pin to ProfileBookmark

Execution time vs. memory consumption (or not?)

Hi all! I’m trying to build some sort of random maze builder in javascript.
I’ve seen some examples on the web, but all of them are the kind of maze that fills all the area, while what I want to do is two random paths starting from 2 points that go on until they touch.
Something like that:
[URL=http://img580.imageshack.us/i/mymazegrid2.png/][IMG]http://img580.imageshack.us/img580/4606/mymazegrid2.png[/IMG][/URL]

Once the two paths have met, the information about flavour will be discharged and everything will look like this:
[URL=http://img811.imageshack.us/i/mymazegrid3.png/][IMG]http://img811.imageshack.us/img811/6213/mymazegrid3.png[/IMG][/URL]

The problem is: I’ve come out with two methods to represent each cell, but I don’t know which one is better.
The first one is to represent the cell like this:

[CODE]
function matrix_map_cell() {
this.connected_to = 0;
this.flavour = 0;
/* DIRECTIONS CAN BE:
* 1 2 3 4 5
* N E NE S NS
*
* 6 7 8 9 10
* SE NSE W NW EW
*
* 11 12 13 14 15
* NEW SW NSW SEW NESW
*/
}
[/CODE]

While the second method is as follows:

[CODE]
function matrix_map_cell() {
this.NORTH = FALSE;
this.SOUTH = FALSE;
this.EAST = FALSE;
this.WEST = FALSE;
this.flavour = 0;
}
[/CODE]

Which way is the best one to represents cell’s connection with adjacent cells? I think the first one uses less memory (using just 1 variable to store directions), but it needs more cpu for being handled (a recursive function is in order to check which directions this cell is connected to), while the second one has opposite behaviour.
Is that true?

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@Franco2authorSep 25.2010 — It just occurred to me that I don't really need to store informations about directions for each cell.

Sometimes, voicing out own's doubts and drawing what you expect to get is the best help. ?
Copy linkTweet thisAlerts:
@rnd_meSep 26.2010 — unless you are talking about millions of cells, performance won't matter very much.

i would go with a grid of cell object that i loop completly through every time. there's not much work to do for empty cells so it shouldn't be that much slower than something that only examines certain cells.

test both your designs and see how much memory changes between the two using Chrome's task manager.

remeber that IE is slow and can only run scripts for 10 seconds, just like the iPhone and android browsers.

don't forget that you only have 10megs of ram to use for JS on the iPhone, not sure about other platforms.
Copy linkTweet thisAlerts:
@Franco2authorSep 26.2010 — Thanks, rnd me. That's reassuring.
×

Success!

Help @Franco2 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...