Node.js와 PHP, Python_node.js의 문자 처리 성능 비교

WBOY
풀어 주다: 2016-05-16 16:42:28
원래의
2376명이 탐색했습니다.

테스트 케이스는 큰 문자열의 문자를 하나씩 읽는 함수와 클래스로 구분됩니다.

테스트 코드

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

기능

<&#63;php
function 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";
&#63;>
로그인 후 복사

카테고리

<&#63;php
class 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";
&#63;>
로그인 후 복사

파이썬

기능

import codecs
import time

def chars(content):
 length = len(content)
 pos = 0
 while(pos < length):
  char = content[pos]
  pos = pos + 1

f = codecs.open('page.html', encoding='utf-8')

content = f.read()

start = time.time()
chars(content)
end = time.time();

print end - start
로그인 후 복사

카테고리

import codecs
import time

class 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.str[self.pos]
   self.pos = self.pos + 1

f = codecs.open('page.html', encoding='utf-8')

content = f.read()

start = time.time()
instance = Chars(content)
instance.run()
end = time.time();

print (end - start)
로그인 후 복사

page.html 파일 내용은 길이가 .

테스트 결과

语言 函数 类
Node.js 0.022s 0.026s
PHP 0.35s 1.02s
Python 0.58s 1.50s
로그인 후 복사

관련 라벨:
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
최신 이슈
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!