Тестовые примеры делятся на функции и классы для чтения символов большой строки один за другим.
Тестовый код
Node.js
функция
var fs = require ("fs"); var content = fs.readfilesync ("page.html", {кодирование: "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", {кодирование: "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 exance = new chars (content); exance.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); $ ancess = new Chars ($ content); $ ancess-> run (); $ end = microTime (true); echo ($ end - $ start). "/n";?>Питон
функция
Импорт CodecSimport TimeDef chars (content): length = len (content) pos = 0 while (pos <length): char = content [pos] pos = pos + 1f = кодеки.
добрый
Импорт CodecSimport TimeClass chars (): def __init __ (self, str): self.str = str self.length = len (str) self.pos = 0 def run (self): while (self.pos <self.length): char = self. = f.read () start = time.time () encement = chars (content) exanter.run () end = time.time (); print (end - start)
Содержимое файла page.html - это текст длины.
Результаты теста
Узел класса языка.