benchmark_to_js 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +1 -0
- data/LICENSE.txt +21 -0
- data/README.md +83 -0
- data/Rakefile +1 -0
- data/benchmark_to_js.gemspec +24 -0
- data/bin/console +7 -0
- data/bin/setup +6 -0
- data/img/bland.png +0 -0
- data/img/pretty.png +0 -0
- data/lib/benchmark_to_js/configuration.rb +26 -0
- data/lib/benchmark_to_js/railtie.rb +8 -0
- data/lib/benchmark_to_js/version.rb +3 -0
- data/lib/benchmark_to_js/view_helpers.rb +28 -0
- data/lib/benchmark_to_js.rb +3 -0
- metadata +88 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 479d8472107c4f042a7e784c953ad551499d9424
|
4
|
+
data.tar.gz: 3beb181cba8a22ba2cb40096a75a5fa2b3987579
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b200b8b9abba932732509b0cd7a6d0016e19c501727c8e64bcac980c1e01f062efbfda3badb64bb5b31829bf4e16ad1d882bc41e89b3129fb13d8e84836392ae
|
7
|
+
data.tar.gz: f72afd1938772a01f40d76b8d0667af843eae506a2634adbebd032747854dd2bc95c35f2fee0a64ce124c1dde4c753d7f5db04343cb7dc1c4e171c9bd352da92
|
data/.gitignore
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, and in the interest of
|
4
|
+
fostering an open and welcoming community, we pledge to respect all people who
|
5
|
+
contribute through reporting issues, posting feature requests, updating
|
6
|
+
documentation, submitting pull requests or patches, and other activities.
|
7
|
+
|
8
|
+
We are committed to making participation in this project a harassment-free
|
9
|
+
experience for everyone, regardless of level of experience, gender, gender
|
10
|
+
identity and expression, sexual orientation, disability, personal appearance,
|
11
|
+
body size, race, ethnicity, age, religion, or nationality.
|
12
|
+
|
13
|
+
Examples of unacceptable behavior by participants include:
|
14
|
+
|
15
|
+
* The use of sexualized language or imagery
|
16
|
+
* Personal attacks
|
17
|
+
* Trolling or insulting/derogatory comments
|
18
|
+
* Public or private harassment
|
19
|
+
* Publishing other's private information, such as physical or electronic
|
20
|
+
addresses, without explicit permission
|
21
|
+
* Other unethical or unprofessional conduct
|
22
|
+
|
23
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
24
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
25
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
26
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
27
|
+
threatening, offensive, or harmful.
|
28
|
+
|
29
|
+
By adopting this Code of Conduct, project maintainers commit themselves to
|
30
|
+
fairly and consistently applying these principles to every aspect of managing
|
31
|
+
this project. Project maintainers who do not follow or enforce the Code of
|
32
|
+
Conduct may be permanently removed from the project team.
|
33
|
+
|
34
|
+
This code of conduct applies both within project spaces and in public spaces
|
35
|
+
when an individual is representing the project or its community.
|
36
|
+
|
37
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
38
|
+
reported by contacting a project maintainer at dave@tanda.co. All
|
39
|
+
complaints will be reviewed and investigated and will result in a response that
|
40
|
+
is deemed necessary and appropriate to the circumstances. Maintainers are
|
41
|
+
obligated to maintain confidentiality with regard to the reporter of an
|
42
|
+
incident.
|
43
|
+
|
44
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
45
|
+
version 1.3.0, available at
|
46
|
+
[http://contributor-covenant.org/version/1/3/0/][version]
|
47
|
+
|
48
|
+
[homepage]: http://contributor-covenant.org
|
49
|
+
[version]: http://contributor-covenant.org/version/1/3/0/
|
data/Gemfile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
source 'https://rubygems.org'
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Dave Allie
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
# BenchmarkToJs
|
2
|
+
|
3
|
+
This gem allows you to benchmark render times for sections of views and partials, and outputs those times to the Javascript console.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'benchmark_to_js'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install benchmark_to_js
|
20
|
+
|
21
|
+
## Configuration
|
22
|
+
|
23
|
+
By default, the benchmarking will only run in the Rails development environment, however this behaviour can be overridden in an initializer along with several other settings.
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
# config/initializers/benchmark_to_js.rb
|
27
|
+
BenchmarkToJs.configure do |config|
|
28
|
+
config.run_in_environments = [:development, :staging] # default [:development]
|
29
|
+
|
30
|
+
# see below for examples on pretty enabled/disabled output
|
31
|
+
config.pretty = true # default true
|
32
|
+
|
33
|
+
# the following only apply if pretty if set to true
|
34
|
+
# minimum milliseconds before time is highlighted in respective colour
|
35
|
+
config.red_threshold = 1000 # default 2000
|
36
|
+
config.orange_threshold = 200 # default 500
|
37
|
+
end
|
38
|
+
```
|
39
|
+
|
40
|
+
Please note that it is **NOT** recommended to configure this gem to run your production environment!
|
41
|
+
|
42
|
+
## Usage
|
43
|
+
|
44
|
+
To use, just wrap a section of a view in a `benchmark_to_js(name)` block, like so:
|
45
|
+
|
46
|
+
### ERB
|
47
|
+
```erb
|
48
|
+
<%= benchmark_to_js("my content") do %>
|
49
|
+
<h1>Some Header</h1>
|
50
|
+
<%= some_intensive_methods %>
|
51
|
+
...
|
52
|
+
<% end %>
|
53
|
+
```
|
54
|
+
|
55
|
+
### Haml
|
56
|
+
```haml
|
57
|
+
= benchmark_to_js("my content") do
|
58
|
+
%h1 Some Header
|
59
|
+
= some_intensive_methods
|
60
|
+
...
|
61
|
+
```
|
62
|
+
|
63
|
+
Both methods will render the content as if it wasn't in the block, and a line will be logged to the Javascript console: `'my content' ran in 123.456ms`.
|
64
|
+
|
65
|
+
If pretty formatting is enabled (it is by default) then your output will look something like this:
|
66
|
+

|
67
|
+
|
68
|
+
and if it isn't, well then it will look bland, like this:
|
69
|
+

|
70
|
+
|
71
|
+
That's all there is to it!
|
72
|
+
|
73
|
+
## Development
|
74
|
+
|
75
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
76
|
+
|
77
|
+
## Contributing
|
78
|
+
|
79
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/benchmark_to_js. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
80
|
+
|
81
|
+
## License
|
82
|
+
|
83
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'benchmark_to_js/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "benchmark_to_js"
|
8
|
+
spec.version = BenchmarkToJs::VERSION
|
9
|
+
spec.authors = ["Dave Allie"]
|
10
|
+
spec.email = ["dave@daveallie.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Benchmarks content in views and logs times to JS console.}
|
13
|
+
spec.description = %q{Benchmarks content in views and logs times to the Javascript console.}
|
14
|
+
spec.homepage = "https://github.com/daveallie/benchmark_to_js"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
end
|
data/bin/console
ADDED
data/bin/setup
ADDED
data/img/bland.png
ADDED
Binary file
|
data/img/pretty.png
ADDED
Binary file
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module BenchmarkToJs
|
2
|
+
class Configuration
|
3
|
+
attr_accessor :run_in_environments, :pretty, :orange_threshold, :red_threshold
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
self.run_in_environments = [:development]
|
7
|
+
self.pretty = true
|
8
|
+
self.orange_threshold = 500
|
9
|
+
self.red_threshold = 2000
|
10
|
+
end
|
11
|
+
|
12
|
+
def run?
|
13
|
+
@run ||= begin
|
14
|
+
defined?(Rails) && Array(self.run_in_environments).map(&:to_s).include?(Rails.env)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.configuration
|
20
|
+
@configuration ||= Configuration.new
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.configure
|
24
|
+
yield(configuration) if block_given?
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module BenchmarkToJs
|
2
|
+
module ViewHelpers
|
3
|
+
def benchmark_to_js(name = 'block', &block)
|
4
|
+
if BenchmarkToJs.configuration.run?
|
5
|
+
ret = ''
|
6
|
+
time = Benchmark.ms {ret = capture(&block)}
|
7
|
+
|
8
|
+
message = if BenchmarkToJs.configuration.pretty
|
9
|
+
color = if time >= BenchmarkToJs.configuration.red_threshold
|
10
|
+
'red'
|
11
|
+
elsif time >= BenchmarkToJs.configuration.orange_threshold
|
12
|
+
'darkorange'
|
13
|
+
else
|
14
|
+
'green'
|
15
|
+
end
|
16
|
+
|
17
|
+
%Q("%c #{escape_javascript(name)} %c ran in %c#{time.round(5)}ms", 'background: #222; color: #bada55', '', 'color:#{color}')
|
18
|
+
else
|
19
|
+
%Q("'#{escape_javascript(name)}' ran in #{time.round(5)}ms")
|
20
|
+
end
|
21
|
+
|
22
|
+
ret + javascript_tag(%Q(console.log(#{message})))
|
23
|
+
else
|
24
|
+
capture(&block)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: benchmark_to_js
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dave Allie
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-03-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.11'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.11'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
description: Benchmarks content in views and logs times to the Javascript console.
|
42
|
+
email:
|
43
|
+
- dave@daveallie.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- CODE_OF_CONDUCT.md
|
50
|
+
- Gemfile
|
51
|
+
- LICENSE.txt
|
52
|
+
- README.md
|
53
|
+
- Rakefile
|
54
|
+
- benchmark_to_js.gemspec
|
55
|
+
- bin/console
|
56
|
+
- bin/setup
|
57
|
+
- img/bland.png
|
58
|
+
- img/pretty.png
|
59
|
+
- lib/benchmark_to_js.rb
|
60
|
+
- lib/benchmark_to_js/configuration.rb
|
61
|
+
- lib/benchmark_to_js/railtie.rb
|
62
|
+
- lib/benchmark_to_js/version.rb
|
63
|
+
- lib/benchmark_to_js/view_helpers.rb
|
64
|
+
homepage: https://github.com/daveallie/benchmark_to_js
|
65
|
+
licenses:
|
66
|
+
- MIT
|
67
|
+
metadata: {}
|
68
|
+
post_install_message:
|
69
|
+
rdoc_options: []
|
70
|
+
require_paths:
|
71
|
+
- lib
|
72
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
requirements: []
|
83
|
+
rubyforge_project:
|
84
|
+
rubygems_version: 2.5.1
|
85
|
+
signing_key:
|
86
|
+
specification_version: 4
|
87
|
+
summary: Benchmarks content in views and logs times to JS console.
|
88
|
+
test_files: []
|