看了一个家伙写的《Is Rails Slow?》的ppt,起了测试模板速度的念头。ppt里测试的是haml比erb快,那么我就测试一下slim和erb之间的速度把。我用的gem版本如下:
gemfile
source 'https://rubygems.org' ruby '2.1.1' # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' gem 'rails', '4.1.1' # Use sqlite3 as the database for Active Record gem 'sqlite3' # Use SCSS for stylesheets gem 'sass-rails', '~> 4.0.3' # Use Uglifier as compressor for JavaScript assets gem 'uglifier', '>= 1.3.0' # Use CoffeeScript for .js.coffee assets and views gem 'coffee-rails', '~> 4.0.0' # See https://github.com/sstephenson/execjs#readme for more supported runtimes # gem 'therubyracer', platforms: :ruby # Use jquery as the JavaScript library gem 'jquery-rails' # Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks gem 'turbolinks' # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder gem 'jbuilder', '~> 2.0' # bundle exec rake doc:rails generates the API under doc/api. gem 'sdoc', '~> 0.4.0', group: :doc # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring gem 'spring', group: :development # Use ActiveModel has_secure_password # gem 'bcrypt', '~> 3.1.7' # Use unicorn as the app server # gem 'unicorn' # Use Capistrano for deployment # gem 'capistrano-rails', group: :development # Use debugger # gem 'debugger', group: [:development, :test] gem 'slim-rails', '2.1.4'
代码如下:
#users_controller.rb class UsersController < ApplicationController layout :false def index @users = User.all.to_a end def show @user = User.find_by_id(params[:id]) end def index_slim @users = User.all.to_a end def show_slim @user = User.find_by_id(params[:id]) end end
routes.rb
resources :users, only: [:index, :show] do member do get :show_slim end collection do get :index_slim end end
index.html.erb
<!DOCTYPE html> <html> <head> <title></title> </head> <body> <table> <tr> <td>Name</td> <td>Phone</td> <td>Address</td> <td>Function</td> </tr> <% @users.each do |user| %> <tr> <td><%= user.name %></td> <td><%= user.phone %></td> <td><%= user.address %></td> <td><%#= link_to "#{user.name}", user_path(user.id) %></td> </tr> <% end -%> </table> </body> </html>
index_slim.html.slim
html head title body table tr td Name td Phone td Address td Function - @users.each do |user| tr td = user.name td = user.phone td = user.address td /= link_to "#{user.name}", show_slim_user_path(user.id)
================快乐的分割线====================================
下面是测试结果:
注释掉了URL helpers的情况下:
slim的速度:
1~3ms之间浮动
Rendered users/index_slim.html.slim (3.0ms) Rendered users/index_slim.html.slim (1.1ms) Rendered users/index_slim.html.slim (3.0ms) Rendered users/index_slim.html.slim (2.1ms) Rendered users/index_slim.html.slim (1.1ms)erb的速度:
2~6ms之间浮动
Rendered users/index.html.erb (2.4ms) Rendered users/index.html.erb (3.7ms) Rendered users/index.html.erb (3.2ms) Rendered users/index.html.erb (5.7ms) Rendered users/index.html.erb (3.0ms)
相关推荐
metasploit 一件安装脚本 源自于 https://raw.githubusercontent.com/rapid7/metasploit-omnibus/master/config/templates/metasploit-framework-wrappers/msfupdate.erb
code 博文链接:https://lj6684.iteye.com/blog/410424
ego - 一个轻量级的模板语言让你可以用Go编写模板。模板可以翻译Go并编译。
粗糙度的一些文献-基于ERB尺度的心理声学模型及其数值计算.pdf 最近研究了哈声品质粗糙度 看了一些文章 特来共享:lol
This method works for me. It's taken from this article. Unfortunately the commands showed there doesn't work because the files that we're supposed to download are not available. So here are the ...
声学感知刻度(mel scale、Bark scale、ERB)与声学特征提取(MFCC、BFCC、GFCC).doc
我们现在支持ST2和ST3。 .base文件 .base文件是项目根目录,其中包含ERB Autocomplete程序包的配置。 { " partials " : " partials " } 我们建议您创建此文件。 如果您不想要,也可以。 我们将使用默认设置。 ...
Laravel开发-erb2blade 将*.erb转换为.blade.php
您可以使用随附的可执行文件html2slim和erb2slim转换文件。 # html2slim -h Usage: html2slim INPUT_FILENAME_OR_DIRECTORY [OUTPUT_FILENAME_OR_DIRECTORY] [options] --trace Show a full traceback on error ...
实际上,不解析Ruby代码是不可能的-Haml支持几种构造,例如=带有=块和Ruby代码中的注释,而ERB则不支持。 可能可以修改Haml引擎,以将Haml的相当大的子集转换为ERB,但是要实现一个不完善的实现,还需要花费大量的...
sql_query, ruby gem 使用ERB从 `.sql.erb` 模板加载SQL查询 sql使用ERB从模板加载SQL查询的ruby gem 。它使使用语法突出显示的纯SQL更加容易。让我们从SQL字符串清除你的ruby 代码。支持的扩展:.sql.erb 或者 .erb...
ERB ::棉绒 可以很容易地在ERB文件中引入错误,未关闭的标签,错误的属性名称,错误的缩进。 ERB :: Lint可以通过将ERB标签变成HTML-ish标签并在结果上运行适当HTML linter来检查这些错误: 原始ERB <%...
奥托尼克斯ERB联轴器英文样本pdf,提供“奥托尼克斯ERB联轴器英文样本”下载,资料主要介绍了ERB联轴器的特点、型号参数及外形尺寸等,可供选型时参考。
格式ERB 通过htmlbeautifier gem提供ERB格式。 支持通过捆绑程序执行htmlbeautifier( bundle exec htmlbeautifier )。
Erubi Erubi是用于ruby的ERB模板引擎。 它是Erubis的简化分支,但有以下区别:使用转义时处理后缀条件(例如,<%= foo,如果bar%>)支持Frozen_string_literErubi¶↑Erubi是ruby的ERB模板引擎。 它是Erubis的...
漂亮的ERB插件 如何安装? yarn add -D prettier @prettier/plugin-ruby prettier-plugin-erb @prettier/plugin-ruby用于格式化多行表达式 对于插件,Ruby可用的配置选项可 如何处理错误? 您的代码格式不正确或...
Erubi是ruby的ERB模板引擎
从合并范围,ERB模板和Hiera数据生成文档 安装 gem install erb-hiera 用法 $ ./bin/erb-hiera --help Options: --config=<s> specify config file --hiera-config=<s> specify hiera config file --dry-run don'...
erb主体结构验收监理小结.doc
Scalate是基于的模板引擎,它支持HAML,Mustache和JSP,Erb和Velocity样式语法。 支持以下模板语言: :是Java / Scala的Mustache模板语言:Haml / Scaml模板语言的翡翠风格 :提供Haml样式模板语言 :提供JSP,Erb...