環境
- OS: Windows7 64bit
- CPU: Core i5 650 (3.2 [GHz])
- RAM: 12 [GB]
- Chrome: 17.0.963.83 m
- IE8(64bit): 8.0.7601.17514
- jQuery: 1.7.2.min
- jQuery.json: 2.3.min
動作
- Stringの配列を作成する。配列の長さは m であり、それぞれ n 文字のアルファベットからなる文字列がセットされている、
- 1.で作成したStringの配列をJSON文字列に変換する。JSON.stringify or jQuery.toJSONメソッドを用いる。
- 2.で作成したJSON文字列を、JavaScript文字列に変換する。JSON.parse or jQuery.parseJSONメソッドを用いる。
- n = 1, 2, 3, ... 10
- m = 20, 21, 22, ..., 219
結果
各シートの記述内容- Chrome: 17.0.963.83 m(JSON) JSON.parse, JSON.stringifyを使用
- Chrome: 17.0.963.83 m(jQuery) $.parseJSON, $.toJSONを使用
- IE8_64:8.0.7601.17514(jQuery) $.parseJSON, $.toJSONを使用
テストコード
$(function(){
function TestCondition(recordLength, recordNumber){
this.isCalculated = false;
this.recordLength = recordLength;
this.recordNumber = recordNumber;
this.spentTime = {
constructJsObject: 0,
serialize: 0,
deserialize: 0
};
}
TestCondition.prototype = {
execute: function(){
var recordString = "";
for(var i=0; i<this.recordLength; i++){
recordString += "X";
}
var rawJsObject = {};
var startTime = new Date();
for(var i=0; i<this.recordNumber; i++){
rawJsObject[i] = new String(recordString);
}
this.spentTime.constructJsObject = new Date() - startTime;
startTime = new Date();
var serialized = $.toJSON(rawJsObject, null)
this.spentTime.serialize = new Date() - startTime;
startTime = new Date();
var deserialized = $.parseJSON(serialized);
var deserialize = new Date() - startTime;
this.spentTime.deserialize = new Date() - startTime;
this.isCalculated = true;
},
writeResult: function(){
var resultTable = $('#resultTable');
var resultRecord = $('<tr></tr>');
resultRecord.append('<td>' + this.recordLength + '</td>');
resultRecord.append('<td>' + this.recordNumber + '</td>');
resultRecord.append('<td>' + this.spentTime.constructJsObject + '</td>');
resultRecord.append('<td>' + this.spentTime.serialize + '</td>');
resultRecord.append('<td>' + this.spentTime.deserialize + '</td>');
resultTable.append(resultRecord);
}
};
for(var i=1; i<11; i++){
for(var j=0; j<20; j++){
var test = new TestCondition(i, Math.pow(2, j));
test.execute();
test.writeResult();
}
}
});
JSON文字列変換後の文字長ぐらい、計算出しておけばよかった。