Web�W���������JavaScript

getElementByID�A�ϐ��Awith�ɂ��Q�Ƒ��x��r

�y�[�W��ɂ���div�^�O���Q�Ƃ���ꍇ�̑��x��r���ʂł��BgetElementById()�ŎQ�Ƃ���ꍇ�A��x�擾����ID��ϐ��ɓ���ĎQ�Ƃ����ꍇ�Awith���g���ăI�u�W�F�N�g�����ȗ������ꍇ��3�p�^�[�����r���Ă��܂��B
�e�X�g�}�V����Power Mac G5 (2GHzx2�A������4GB)�AWindows��XP SP2 (3.0GHz�A768MB) �ōs���Ă��܂��B���쑬�x�͉��x�������[�h�����ꍇ�̒l�ɂȂ��Ă��܂��B�܂��A���쑬�x�͊‹��ɂ��قȂ�̂ŁA�����܂ł��Q�l���x�ɂ��Ă��������B
�y�T���v��1�����s�z
�y�T���v��2�����s�z
�y�T���v��3�����s�z
OS�u���E�UgetElementById (msec)�ϐ� (msec)with (msec)
MacOS X (10.4.7)Safari 2.0.412804201000
MacOS X (10.4.7)Firefox 1.5.0.4445030504420
MacOS X (10.4.7)Opera 9.02770501160
Windows XP SP2Internet Explorer 6440023002760
Windows XP SP2Firefox 1.5.0.4462030324100
Windows XP SP2Opera 9.068015580
�y�T���v���P�z
��HTML�t�@�C��
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<script type="text/javascript" src="test.js"></script>
<title>Sample</title>
</head>
<body>
<p>JavaScript Speed Test</p>
<div id="outputArea"></div>
</body>
</html>

���X�N���v�g�t�@�C�� (test.js)
window.onload = function() {
var num = 100000;
s = (new Date()).getTime();
for (var i=0; i<num; i++) {
document.getElementById("outputArea").innerHTML;
}
e = (new Date()).getTime();
alert(e-s);
}
�y�T���v���Q�z
��HTML�t�@�C��
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<script type="text/javascript" src="test.js"></script>
<title>Sample</title>
</head>
<body>
<p>JavaScript Speed Test</p>
<div id="outputArea"></div>
</body>
</html>

���X�N���v�g�t�@�C�� (test.js)
window.onload = function() {
var divObj = document.getElementById("outputArea");
var num = 100000;
s = (new Date()).getTime();
for (var i=0; i<num; i++) {
divObj.innerHTML;
}
e = (new Date()).getTime();
alert(e-s);
}
�y�T���v���R�z
��HTML�t�@�C��
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<script type="text/javascript" src="test.js"></script>
<title>Sample</title>
</head>
<body>
<p>JavaScript Speed Test</p>
<div id="outputArea"></div>
</body>
</html>

���X�N���v�g�t�@�C�� (test.js)
window.onload = function() {
var divObj = document.getElementById("outputArea");
var num = 100000;
s = (new Date()).getTime();
with(document.getElementById("outputArea")) {
for (var i=0; i<num; i++) {
innerHTML;
}
}
e = (new Date()).getTime();
alert(e-s);
}