模板引擎之EJS/Hogan/Jade/Handlebars性能对比

最近抽空对EJS/Hogan/Jade/Handlebars等几个模板引擎做了些性能对比,下面发出对比结果。

先来说一下测试环境,
同一台机器,同样的环境,页面输出也就是最基础的Hello页面,模板功能中只使用了变量;
测试参数为ab -c 300 -t 10 http://127.0.0.1:5000/

========================= 割 =========================

下面4个结果都是在开发模式下的测试:

EJS:

This is ApacheBench, Version 2.3 <$Revision: 1528965 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 127.0.0.1 (be patient)


Server Software:        
Server Hostname:        127.0.0.1
Server Port:            5000

Document Path:          /
Document Length:        207 bytes

Concurrency Level:      300
Time taken for tests:   10.001 seconds
Complete requests:      5181
Failed requests:        0
Total transferred:      2015409 bytes
HTML transferred:       1072467 bytes
Requests per second:    518.04 [#/sec] (mean)
Time per request:       579.107 [ms] (mean)
Time per request:       1.930 [ms] (mean, across all concurrent requests)
Transfer rate:          196.79 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0  232 832.7      0    7015
Processing:   171  303  65.0    279     704
Waiting:      168  303  65.0    279     704
Total:        188  536 846.8    285    7430

Percentage of the requests served within a certain time (ms)
  50%    285
  66%    359
  75%    378
  80%    389
  90%   1249
  95%   1452
  98%   3369
  99%   3476
 100%   7430 (longest request)

Jade:

This is ApacheBench, Version 2.3 <$Revision: 1528965 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 127.0.0.1 (be patient)


Server Software:        
Server Hostname:        127.0.0.1
Server Port:            5000

Document Path:          /
Document Length:        170 bytes

Concurrency Level:      300
Time taken for tests:   10.001 seconds
Complete requests:      1740
Failed requests:        0
Total transferred:      612480 bytes
HTML transferred:       295800 bytes
Requests per second:    173.98 [#/sec] (mean)
Time per request:       1724.298 [ms] (mean)
Time per request:       5.748 [ms] (mean, across all concurrent requests)
Transfer rate:          59.81 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0  417 677.9      0    3005
Processing:   172  998 231.3    972    3960
Waiting:      170  998 231.3    972    3960
Total:        190 1415 730.5   1109    4959

Percentage of the requests served within a certain time (ms)
  50%   1109
  66%   1704
  75%   1876
  80%   1937
  90%   2233
  95%   2675
  98%   3962
  99%   4015
 100%   4959 (longest request)

Hogan:

This is ApacheBench, Version 2.3 <$Revision: 1528965 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 127.0.0.1 (be patient)


Server Software:        
Server Hostname:        127.0.0.1
Server Port:            5000

Document Path:          /
Document Length:        206 bytes

Concurrency Level:      300
Time taken for tests:   10.001 seconds
Complete requests:      5213
Failed requests:        0
Total transferred:      2022644 bytes
HTML transferred:       1073878 bytes
Requests per second:    521.25 [#/sec] (mean)
Time per request:       575.536 [ms] (mean)
Time per request:       1.918 [ms] (mean, across all concurrent requests)
Transfer rate:          197.51 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0  170 627.3      0    3005
Processing:   167  356 106.2    335     693
Waiting:      164  356 106.2    335     693
Total:        193  527 653.1    353    3685

Percentage of the requests served within a certain time (ms)
  50%    353
  66%    470
  75%    476
  80%    479
  90%    492
  95%   1345
  98%   3453
  99%   3498
 100%   3685 (longest request)

Handlebars:

This is ApacheBench, Version 2.3 <$Revision: 1528965 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 127.0.0.1 (be patient)


Server Software:        
Server Hostname:        127.0.0.1
Server Port:            5000

Document Path:          /
Document Length:        204 bytes

Concurrency Level:      300
Time taken for tests:   10.061 seconds
Complete requests:      3358
Failed requests:        0
Total transferred:      1296188 bytes
HTML transferred:       685032 bytes
Requests per second:    333.76 [#/sec] (mean)
Time per request:       898.854 [ms] (mean)
Time per request:       2.996 [ms] (mean, across all concurrent requests)
Transfer rate:          125.81 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0   61 242.8      0    3001
Processing:   457  790  72.4    801    1044
Waiting:      454  790  72.4    800    1044
Total:        467  852 255.3    803    3806

Percentage of the requests served within a certain time (ms)
  50%    803
  66%    809
  75%    816
  80%    821
  90%    868
  95%   1730
  98%   1793
  99%   1828
 100%   3806 (longest request)

========================= 割 =========================

下面4个结果都是在生产模式下的测试:

EJS:

This is ApacheBench, Version 2.3 <$Revision: 1528965 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 127.0.0.1 (be patient)


Server Software:        
Server Hostname:        127.0.0.1
Server Port:            5000

Document Path:          /
Document Length:        207 bytes

Concurrency Level:      300
Time taken for tests:   10.001 seconds
Complete requests:      11147
Failed requests:        0
Total transferred:      4336183 bytes
HTML transferred:       2307429 bytes
Requests per second:    1114.64 [#/sec] (mean)
Time per request:       269.144 [ms] (mean)
Time per request:       0.897 [ms] (mean, across all concurrent requests)
Transfer rate:          423.43 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0   97 400.7      0    3005
Processing:   104  155  49.4    138     638
Waiting:      104  155  49.4    137     638
Total:        104  252 408.3    144    3642

Percentage of the requests served within a certain time (ms)
  50%    144
  66%    187
  75%    199
  80%    224
  90%    233
  95%   1140
  98%   1220
  99%   3117
 100%   3642 (longest request)

Jade:

This is ApacheBench, Version 2.3 <$Revision: 1528965 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 127.0.0.1 (be patient)


Server Software:        
Server Hostname:        127.0.0.1
Server Port:            5000

Document Path:          /
Document Length:        170 bytes

Concurrency Level:      300
Time taken for tests:   10.001 seconds
Complete requests:      10023
Failed requests:        0
Total transferred:      3528096 bytes
HTML transferred:       1703910 bytes
Requests per second:    1002.25 [#/sec] (mean)
Time per request:       299.327 [ms] (mean)
Time per request:       0.998 [ms] (mean, across all concurrent requests)
Transfer rate:          344.52 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0   51 273.5      0    3005
Processing:   120  243  74.8    250     782
Waiting:      119  242  74.8    250     781
Total:        120  294 279.3    251    3270

Percentage of the requests served within a certain time (ms)
  50%    251
  66%    253
  75%    254
  80%    256
  90%    277
  95%    730
  98%   1219
  99%   1249
 100%   3270 (longest request)

Hogan:

This is ApacheBench, Version 2.3 <$Revision: 1528965 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 127.0.0.1 (be patient)


Server Software:        
Server Hostname:        127.0.0.1
Server Port:            5000

Document Path:          /
Document Length:        206 bytes

Concurrency Level:      300
Time taken for tests:   10.000 seconds
Complete requests:      11419
Failed requests:        0
Total transferred:      4430572 bytes
HTML transferred:       2352314 bytes
Requests per second:    1141.87 [#/sec] (mean)
Time per request:       262.726 [ms] (mean)
Time per request:       0.876 [ms] (mean, across all concurrent requests)
Transfer rate:          432.66 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0  130 376.4      0    3004
Processing:   101  123  32.5    111     919
Waiting:      101  123  32.5    111     918
Total:        101  253 388.8    111    3151

Percentage of the requests served within a certain time (ms)
  50%    111
  66%    120
  75%    128
  80%    137
  90%   1124
  95%   1154
  98%   1206
  99%   1213
 100%   3151 (longest request)

Handlebars:

This is ApacheBench, Version 2.3 <$Revision: 1528965 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 127.0.0.1 (be patient)


Server Software:        
Server Hostname:        127.0.0.1
Server Port:            5000

Document Path:          /
Document Length:        204 bytes

Concurrency Level:      300
Time taken for tests:   10.000 seconds
Complete requests:      5582
Failed requests:        0
Total transferred:      2154652 bytes
HTML transferred:       1138728 bytes
Requests per second:    558.18 [#/sec] (mean)
Time per request:       537.460 [ms] (mean)
Time per request:       1.792 [ms] (mean, across all concurrent requests)
Transfer rate:          210.41 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0   31 171.4      0    1001
Processing:   273  497  45.9    489     701
Waiting:      273  497  45.8    489     700
Total:        273  528 177.8    489    1671

Percentage of the requests served within a certain time (ms)
  50%    489
  66%    499
  75%    520
  80%    527
  90%    551
  95%    589
  98%   1454
  99%   1500
 100%   1671 (longest request)

虽然测试不是很严谨,但起码可以得出一个结论:
开发环境其实可以忽略性能的,所以就不作总结了;
生产环境下,EJS与Hogan差不多,它们比Jade略好,比Handlerbars好很多

本地对比没有包括Swig,Swig的性能据说也不比EJS差的,有兴趣的童鞋可以自己测试下^_^

此条目发表在原创空间分类目录,贴了, , , 标签。将固定链接加入收藏夹。

发表评论