Skip to content

Instantly share code, notes, and snippets.

@dgynn
dgynn / mem_lite.rb
Created September 5, 2017 04:18
Test MemoryProfiler with possible mem_lite option
#!/usr/bin/env ruby
# This script can be run against a local version of MemoryProfiler or the latest release for comparison
# Run at least once with --install-gems to ensure all required Gems are installed
# ruby ./mem_lite.rb --install-gems
#
# To run against local code
# ruby ./mem_lite.rb --local
# To run against latest release
# ruby ./mem_lite.rb
#
@dgynn
dgynn / wildcard_route_watcher.rb
Created January 9, 2017 18:22
Wildcard route watcher for Rails
+# This can be added to initializer to add logging
+# on the wildcard route such as this...
+# match ':controller(/:action(/:id))(.:format)', :via => :all, :as => 'wildcard'
+# Name the route 'wildcard'
+
+module WildcardRouteWatcher
+ def find_routes(req)
+ routes = super
+ if routes.size > 0
+ _match, parameters, route = routes[0]
This file has been truncated, but you can view the full file.
# frozen_string_literal: true
require 'digest/sha2'
require 'benchmark'
require 'set'
module HashDigestUtils
extend self
ADD_VALUE_TO_DIGEST = {
@dgynn
dgynn / benchmark.rb
Last active August 28, 2016 04:43
Awesome Print profiling script
#!/usr/bin/env ruby
# This script is licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
# Feel free to copy, modify, reuse as you would like without limitation.
#
# Save this file to the root directory where the awesome_print code is checked out.
#
# This script profiles the impact of awesome_print on taking difference of two arrays
# [1,2,3,4,5] - [3,4,5,6,7]
# The script measures memory allocations and iterations/sec before and after
# awesome_print has been loaded to demonstrate the impact
@dgynn
dgynn / benchmark.rb
Last active June 13, 2016 04:43
Rabl benchmarking script
#!/usr/bin/env ruby
# Copy this file to a ./benchmarks directory where the rabl code is checked out.
# On the first run, it will create a `posts.json.rabl` template. You can edit
# that file and re-run to see the effect of different templates.
# This benchmark script creates a sqlite DB and ActiveRecord objects for
# 10 Posts with 5 Comments that are then serialized using Rabl.
# This script can be run against a local version of Rabl or the latest release for comparison
# Run at least once with --install-gems to ensure all required Gems are installed
# ruby ./benchmark.rb --install-gems
# To run benchmark against local code
@dgynn
dgynn / benchmark_profiler2.rb
Created February 28, 2016 17:38
Benchmark script for checking the impact of individual ruby-prof profiler changes
# To run benchmark...
# rake clean
# rake compile
# ruby benchmarks/benchmark_profiler2.rb
begin
require 'bundler/inline'
rescue LoadError => e
$stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler'
raise e
@dgynn
dgynn / benchmark_profiler.rb
Created February 28, 2016 04:39
Benchmark script for ruby-prof profiler changes
# This benchmark script profiles a relatively simple 2-table ActiveRecord
# transaction to an in-memory database to generate a profile report.
# The script only benchmarks profiling, and not report printing.
# Save this file as ./benchmarks/benchmark_profiler.rb
# Run with `ruby ./benchmarks/benchmark_profiler`
begin
require 'bundler/inline'
rescue LoadError => e
@dgynn
dgynn / benchmark_switchman.rb
Last active December 30, 2015 20:16
Benchmark script for switchman tuning investigations
#!/usr/bin/env ruby
# To use this benchmark script, add a Gemfile.d/profiling.rb file with...
# gem 'memory_profiler'
# gem 'benchmark-ips'
# gem 'ruby-prof'
# This benchmark script file should be placed in the canvas-lms root directory
# and run as ./benchmark_switchman.rb <run_identifier>
# The identifier is optional and allows you to compare multiple runs more easily.
@dgynn
dgynn / benchmark_suspend.rb
Created November 27, 2015 05:08
Benchmark script for activesupport-suspend_callbacks improvements
#!/usr/bin/env ruby
# To use this benchmark script, add a Gemfile.d/profiling.rb file with...
# gem 'memory_profiler'
# gem 'benchmark-ips'
# gem 'ruby-prof'
# This benchmark script file should be placed in the canvas-lms root directory
# and run as ./benchmark_suspend.rb <run_identifier>
# The identifier is optional and allows you to compare multiple runs more easily.
@dgynn
dgynn / benchmark.rb
Created July 27, 2015 02:55
CanCan performance tuning benchmark
#!/usr/bin/env ruby
begin
require 'bundler/inline'
rescue LoadError => e
$stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler'
raise e
end
# Change this to true if you do not have the gems installed