Mercurial > op > Looping
changeset 9:30b521e712f5 >>178
JavaScript (xhtml) のソースコードを追加。
author | "uncorrelated zombie" <uncorrelated@yahoo.co.jp> |
---|---|
date | Wed, 23 Feb 2011 01:17:31 +0900 |
parents | 30da8c1da4d4 |
children | 308cc64c24b9 |
files | Looping.xhtml |
diffstat | 1 files changed, 55 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Looping.xhtml Wed Feb 23 01:17:31 2011 +0900 @@ -0,0 +1,55 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja" lang="ja"> +<head> +<title>Looping</title> +<script type="text/javascript"><![CDATA[ + +var Looping = function(){ + this.n0 = 0; + this.calc = function(n){ + var n1 = this.n0 + (1 - 2*(n%2)); + this.n0 = n; + return n1; + }; +}; + +function benchmark(){ + + document.forms[0].elements["text1"].value = ""; + document.forms[0].elements["text2"].value = ""; + var o = new Looping(); + var n = 1; + var st = new Date(); + for(var c=0;c<2147483647;c++){ + n = o.calc(n); + } + var et = new Date(); + document.forms[0].elements["text1"].value = n; + document.forms[0].elements["text2"].value = (et - st)/1000; +} + +]]></script> +<style type="text/css"> +input { width: 100%; } +</style> +</head> +<body> +<form> +<div style="width:320px;"> + <div style="margin:4px;"> + 計算結果 + <input type="text" name="text1" value="" /> + </div> + <div style="margin:4px;"> + 経過時間 + <input type="text" name="text2" value="" /> + </div> + <div style="margin:4px;"> + <input type="button" value="実行" onclick="benchmark();" /> + </div> +</div> +</form> +</body> +</html>