这个问题关于javascript语言。 简单地认为我们有一个地图,我们插入项目如下方式JS对象阵列vs JS对象阵列效率和性能
var dataMap=new Map();
//First Mechanism
//firstly we can think of structure of values of map can be JSONArray of objects
dataMap.set("key1",[{'id':12,'name':"obj1"}]); // init
// and,then insert new element to JSON Array which holds by map using 'key1'
dataMap.get("key1").push({'id':23,'name':"obj47"});//updated, now value of 'key1' is an JSON array which holds two elements
// expect 'key1' -> [{'id':12,'name':"obj1"},{'id':23,'name':"obj47"}]
//Second mechanism
// next we cant think of structure of values of map as JSONObject of Arrays
dataMap.set("key1",{'id':[12],'name':["obj1"]}); // init
// then we proceed with update operations like this
dataMap.get("key1").id.push(23);
dataMap.get("key1").name.push("obj47"); // two operations to insert items to respective arrays.
// expect 'key1' ->{'id':[12,23],'name':["obj1","obj47"]}
哪种方法最有效?
认为我们有相当数量的插入操作到地图,如果我们在表现哪一个更好?
(如果我犯了错请纠正,我想尽可能简化问题,因为我可以这样做) 谢谢。
这两种方法都会导致不同的输出,因此取决于您打算如何使用此阵列。 – gurvinder372
@ gurvinder372这就是我之前想的。但是如何确定每种方法的性能? – Buddhika
@Buddhika:表现不是问题。这取决于什么更容易使用你。这就是___基于观点的.__ – Cerbrus