I would recommend against relying on a specifying datatable implementation
(which anyway can change without notice), but instead perform your own
profiling depending on your own use case.
For example, a test like the one at the bottom, with a 2000x2000 datatable,
yields the following results on Chrome 13 (current beta):
colmajor iteration alone : ~1sec
rowmajor iteration alone: ~400ms
rowmajor followed by colmajor: ~500ms followed by ~1.2sec
colmajor followed by rowmajor : ~1s followed by ~800ms
(mind that I've run the tests only a few times, so numbers are not
necessarily stable).
The last one in particular suggests that Chrome, at least, performs some
optimizations / caching out of your control (the same code behaves
differently depending on which order we iterate first), hence I insist that
your best option is to profile your own code and see what option works best
in your scenario.
/R.
benchmark:
console.time('creation');
var n = 2000;
var d = [];
var header = [];
for (var i = 0; i < n; i++) {
header.push('hdr');
}
d.push(header);
for (var i = 0; i < n; i++) {
var row = [];
for (var j = 0; j < n; j++) {
row.push(Math.random());
}
d.push(row);
}
data = google.visualization.arrayToDataTable(d);
console.timeEnd('creation');
console.log(data.getNumberOfRows());
console.time('colmajor');
res = [];
for (var col = 0; col < n; col++) {
for (var row = 0; row < n; row++) {
res.push(data.getValue(row, col));
}
}
console.timeEnd('colmajor');
console.time('rowmajor');
res = [];
for (var row = 0; row < n; row++) {
for (var col = 0; col < n; col++) {
res.push(data.getValue(row, col));
}
}
console.timeEnd('rowmajor');
--
You received this message because you are subscribed to the Google Groups
"Google Visualization API" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/google-visualization-api/-/BJlimDSgpGIJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-visualization-api?hl=en.