comparison Looping.xhtml @ 9:30b521e712f5 >>178

JavaScript (xhtml) のソースコードを追加。
author "uncorrelated zombie" <uncorrelated@yahoo.co.jp>
date Wed, 23 Feb 2011 01:17:31 +0900
parents
children
comparison
equal deleted inserted replaced
8:30da8c1da4d4 9:30b521e712f5
1 <?xml version="1.0" encoding="UTF-8"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
3 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
4 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja" lang="ja">
5 <head>
6 <title>Looping</title>
7 <script type="text/javascript"><![CDATA[
8
9 var Looping = function(){
10 this.n0 = 0;
11 this.calc = function(n){
12 var n1 = this.n0 + (1 - 2*(n%2));
13 this.n0 = n;
14 return n1;
15 };
16 };
17
18 function benchmark(){
19
20 document.forms[0].elements["text1"].value = "";
21 document.forms[0].elements["text2"].value = "";
22 var o = new Looping();
23 var n = 1;
24 var st = new Date();
25 for(var c=0;c<2147483647;c++){
26 n = o.calc(n);
27 }
28 var et = new Date();
29 document.forms[0].elements["text1"].value = n;
30 document.forms[0].elements["text2"].value = (et - st)/1000;
31 }
32
33 ]]></script>
34 <style type="text/css">
35 input { width: 100%; }
36 </style>
37 </head>
38 <body>
39 <form>
40 <div style="width:320px;">
41 <div style="margin:4px;">
42 計算結果
43 <input type="text" name="text1" value="" />
44 </div>
45 <div style="margin:4px;">
46 経過時間
47 <input type="text" name="text2" value="" />
48 </div>
49 <div style="margin:4px;">
50 <input type="button" value="実行" onclick="benchmark();" />
51 </div>
52 </div>
53 </form>
54 </body>
55 </html>