1

I need to store stock market data for manipulation. Which is more efficient,

1) STORING DATA AS MULTIDIMENSION ARRAY FOR OPEN,HIGH,LOW,CLOSE,date AS IN

//Data array stored in a array
var tickdata = new Array();
tickdata.push([open,high,low,close,volume,date])

2) storing data as an object object as shown below

function dailyData(open, high, low, close,volume,date)
{
   this.open = open;
   this.high = high;
   this.low = low;
   this.close = close;
   this.volume=volume;
   this.date=date;
}
var data = new Array();
data[0] = new dailyData(1017.50,1032.50 ,997.50, 1025.40,4187510,'07-Jan-2005');
3
  • 1
    Don't worry about this type of efficiency. It always varies between implementations anyway. Do whatever makes the most sense for the task at hand. Commented Mar 5, 2013 at 6:39
  • What does efficient mean for you? Efficient in space? Efficient in access time? Efficient in how fast you can code it? Commented Mar 5, 2013 at 6:43
  • @ Josiah Hester I mean efficiency here as access time.. I will do lot of access.. so will using as object will have some overhead..? If you say it depends on implementation.. I need efficient approach for chrome Commented Mar 5, 2013 at 7:30

1 Answer 1

1

The second is easier to maintain in my opinion since you could edit setting values to change behavior.

The first option is harder to read, consider the following:

function sortData(data,index){
  data.sort(function(a,b){
   if(a[index]>b[index]){return 1;}
   if(a[index]<b[index]){return -1;}
   return 0;
  });
}
sortData(data,0);// sorts on open

where the second option might be easier to read:

function sortData(data,index){
  data.sort(function(a,b){
   if(a[index]>b[index]){return 1;}
   if(a[index]<b[index]){return -1;}
   return 0;
  });
}
sortData(data,"open");// sorts on open

Especially if you want to sort on multiple columns. Getting values is obviously easier to read: data[0][0] or data[0]["open"] or data[0].open

Formatting output cold easily be done with:

function dailyData(open, high, low, close,volume,date){
   //checking if data is valid comes here, maybe setting the
   // right type for the values (like date as date instead of string)
   this.open = open;
   this.high = high;
   this.low = low;
   this.close = close;
   this.volume=volume;
   this.date=date;
   this._dateYear={
      rerurn this.date.getFullYear();
   }
   this.dateYear=this._dateYear();
}

To (not) answer your question: I'm not sure if you would get performance loss using option 2 but I've used large arrays of objects and even on older browsers didn't have a problem with it.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.