LoginSignup
16
16

More than 5 years have passed since last update.

最速Template EngineのECTは本当に速かった。レスポンスを60倍早くした話【Node.js】

Last updated at Posted at 2015-01-10

爆速テンプレートエンジンECTのご紹介

ECTとは

  • Fastest JavaScript template engine with embedded CoffeeScript syntax
  • 公式が下記のベンチマークを出しています。圧倒的...!
Rendering 100000 templates:

ECT
  Escaped   : 2180ms
  Unescaped : 133ms
  Total     : 2313ms

EJS without `with`
  Escaped   : 4526ms
  Unescaped : 485ms
  Total     : 5011ms

Underscore
  Escaped   : 5775ms
  Unescaped : 2486ms
  Total     : 8261ms

EJS
  Escaped   : 6316ms
  Unescaped : 2734ms
  Total     : 9050ms

Jade without `with`
  Escaped   : 8566ms
  Unescaped : 2982ms
  Total     : 11548ms

Jade
  Escaped   : 18330ms
  Unescaped : 12095ms
  Total     : 30425ms
  • クライアントサイドでも動作します。
  • githubの最終更新が 9 Jun 2014 なのが少し気になりましたが、私の場合移植しても問題は発生しませんでした。

ペロッ...これはCoffeeScript!!

  • 本当にcoffeescriptっぽく記述できます。例えば以下
# 存在確認演算子も後置のifもなんのその
<%= @head.title if @head?.title %>
# 組込み関数だって普通に使えます
<% now = new Date(); strDate = now.getFullYear() + '年' + (now.getMonth() + 1) + '月' + now.getDate() + '日'; %>
<%- strDate %> # 例) 2015年1月10日
# loopは for ~ in で統一(配列だからfor in, ハッシュだからfor of, は無い)
<% for item in @items : %>
  <%= item.name %>
<% end %>
  • こんな便利な機能も
# includeするテンプレートにobjectを食わせることが可能。超便利(Partials)
<% include 'hoge.ect', { foo: 'bar', title: 'hello' } %>

結び

  • Jadeを投げ捨ててECTを使ってみては如何でしょうか。
Jade 1.7.0 ECT 0.5.9
620 ms 10 ms
16
16
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
16
16