テストケースは関数とクラスに分かれており、大きな文字列の文字を1つずつ読み取ります。
テストコード
node.js
関数
var fs = require( "fs"); var content = fs.readfilesync( "page.html"、{encoding: "utf-8"}); function chars(content){var length = content.length; var pos = 0; while(pos ++ <length){var chr = content [pos -1]; }} var start = date.now(); chars(content); var end = date.now(); console.log(end -start);親切
var fs = require( "fs"); var content = fs.readfilesync( "page.html"、{encoding: "utf-8"}); var chars = function(str){this.str = str; this.length = str.length this.pos = 0;} chars.prototype.run = function(){while(this.pos ++ <this.length){var chr = this.str [this.pos -1]; }} var start = date.now(); var instance = new chars(content); instance.run(); var end = date.now(); console.log(end -start);Php
関数
<?phpfunction chars($ content){$ length = strlen($ content); $ pos = 0; while($ pos ++ <$ length){$ char = $ content {$ pos -1}; }} $ content = file_get_contents( "page.html"); $ start = microtime(true); chars($ content); $ end = microtime(true); echo($ end -$ start)。 "/n";?>親切
<?phpclass chars {public function __construct($ str){$ this-> str = $ str; $ this-> length = strlen($ str); $ this-> pos = 0; } public function run(){while($ this-> pos ++ <$ this-> length){$ char = $ this-> str {$ this-> pos-1}; }}} $ content = file_get_contents( "page.html"); $ start = microtime(true); $ instance = new chars($ content); $ instance-> run(); $ end = microtime(true); echo($ end -$ start)。 "/n";?>Python
関数
Import codecsimport timedef chars(content):length = len(content)pos = 0 while(pos <length):char = content [pos] pos = pos + 1f = codecs.open( 'page.html'、encoding = 'utf -8')content = f.read()start = time.time()end = end = time。
親切
Codecsimport Timeclass Chars():def __init __(self、str):self.str = str self.lenge = len(str)self.pos = 0 def run(self):while(self.pos <self.lenges):char = self.str [self.pos] self.pos = self.self.pos + 1f = codecs( 'page.html」 f.read()start = time.time()instance = chars(content)instance.run()end = time.time(); print(end -start);
page.htmlファイルコンテンツは長さのテキストです。
テスト結果
言語関数クラスnode.js 0.022S 0.026sphp 0.35s 1.02Spython 0.58S 1.50S