Answer the question
In order to leave comments, you need to log in
How to optimize a set into a buffer array?
Good afternoon!
I have a question about code optimization.
The goal is to understand how to reduce the amount of code in Example 1 without significantly reducing performance.
Branchmark: https://jsben.ch/OsKbY
Setup:
let data1={test:new Float32Array(50000)}
let data2={test:new Float32Array(50000)}
function setBuffer(name, figure_num, data_p){
let num = 5 * figure_num
let buffer_array = data1[name]
for (let i = 0, l = data_p.length; i < l; i++) {
buffer_array[num + i] = data_p[i];
}
}
let pt1=[1,2]
let pt2=[3,4]
let status=5
for(let i=0;i<10000;i++){
let buffer_array = data2['test']
let num = 5*i;
buffer_array[num+0] = pt1[0];
buffer_array[num+1] = pt1[1];
buffer_array[num+2] = pt2[0];
buffer_array[num+3] = pt2[1];
buffer_array[num+4] = status;
}
let pt1=[1,2]
let pt2=[3,4]
let status=5
for(let i=0;i<10000;i++){
setBuffer('test', i, [pt1[0],pt1[1],pt2[0],pt2[1],status])
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question