1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| <!doctype html>
<html lang="fr">
<head>
<meta charset="utf-8" />
<title>with</title>
<style>
</style>
</head>
<body>
<div id="div1">Div de test</div>
<button onclick="testWith()">Lancer le test</button>
<script type="text/javascript">
function testWith(){
var divTest, resultat, i;
var t = new Date().getTime();
for(i=0; i < 1000000; i++){
with(document){
divTest = getElementById('div1');
}
}
resultat = (new Date().getTime() - t) + ' ms\n';
t = new Date().getTime();
for(i=0; i < 1000000; i++){
divTest = document.getElementById('div1');
}
resultat += (new Date().getTime() - t) + ' ms';
alert(resultat);
}
</script>
</body> |
Partager