Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

need to increase the speed of 2

Status
Not open for further replies.

tester321

Programmer
Mar 13, 2007
150
0
0
CA
Hi, i'm working with google map api, i created a function to display marker info on the map, but its a bit slow under stress test. Any thoughts on zipping thru the function quicker... may readjusting the loging of such function, here it is, any thoughts? thanks

Code:
        function GenOtherMark() {
			for(i=0;i<OtherMarkData.length;i++) {
				var Mark=new GMarker(new GLatLng(OtherMarkData[i].lattitude,OtherMarkData[i].longitude));
				Mark.ObjectX=OtherMarkData[i];
				OtherMarkArray[i]=Mark;
				Mark.getIcon().image=strDefaultMark;
				if((Mark.ObjectX!=null)&&(OtherMarkData[i].murl.length>0)) {
					Mark.getIcon().image=Mark.ObjectX.murl;
				}
				GEvent.addListener(OtherMarkArray[i], "click", Event_Mark_Click)
				GEvent.addListener(OtherMarkArray[i], "dragstart", Event_Mark_Drag_Start);
				GEvent.addListener(OtherMarkArray[i], "dragend", Event_Mark_Drag_Stop);
				GEvent.addListener(OtherMarkArray[i], "mouseover", Event_Mark_MouseOver);
				GEvent.addListener(OtherMarkArray[i], "mouseout", Event_Mark_MouseOut);
				map.addOverlay(OtherMarkArray[i]);
			}
        }
 
A quick win:
Code:
for(i=0[!],max=[/!]OtherMarkData.length;[!]i<max[/!];i++) {
Maybe set the default image for the mark in the constructor for GMarker instead of assigning it here as well?

Cheers,
Jeff


[tt]Jeff's Page [!]@[/!] Code Couch
[/tt]

Make sure your web page and css validates properly against the doctype you have chosen - before you attempt to debug a problem!

FAQ216-6094
 
Jeff, would counting down be quicker than counting up; i-- instead of i++

any thoughts on this? thx
 
I don't see any reason for it to be faster one way or the other. I've certainly not seen it switched from one to the other for optimization reasons.

Cheers,
Jeff


[tt]Jeff's Page [!]@[/!] Code Couch
[/tt]

Make sure your web page and css validates properly against the doctype you have chosen - before you attempt to debug a problem!

FAQ216-6094
 
Hi, I have 1 more that i need suggestions on speeding up, any thoughts on this one:

Code:
function Event_Map_Gohere(lattitude,longitude,Zoom,MarkerID) {
	map.setCenter(new GLatLng(lattitude,longitude),Number(Zoom));
	var isfound=false;

	for(i=0,max=gMarkData.length;i<max;i++) {
		if(gMarkData[i].MarkerID==MarkerID) {
			isfound=true
			xMark=gMarkArray[i]
			break;
		}
	}
	if(!isfound) {
	for(i=0,max=OtherMarkData.length;i<max;i++) {
			if(OtherMarkData[i].MarkerID==MarkerID) {
				isfound=true
				xMark=OtherMarkArray[i]
				break;
			}
		}
	}
	if(isfound) {
		map.closeInfoWindow();
		if(xMark.ObjectX.UserID==userID) {
			isShowInfoWin=true
			xMark.openInfoWindowTabsHtml([GetInfoTab(xMark.ObjectX),GetSearchTab(xMark.ObjectX),GetAdminTab(xMark.ObjectX)]);
			InitiateMarkerPolicy(xMark.ObjectX);
		} else {
			isShowInfoWin=true
			xMark.openInfoWindowTabsHtml([GetInfoTab(xMark.ObjectX),GetSearchTab(xMark.ObjectX)]);
		}
	}
}

Thanks again!!
 
There's probably not a huge amount you can do to get a great increase out of that - maybe if we knew how the JavaScript engines worked you might be able to save a few clock cycles here or there, but I don't think there's much in it.

I remember read an article that talks about optiising loops, and I'm sure it found that going backwards (x--) instead of forwards (x++) was more efficient. I'll see if I can dig it out, as it was by a really switched on bunch of guys over at the Ozone Asylum (
Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
 
Thanks Dan, it been going much better using some of the references and the debugger.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top