Skip to content

Instantly share code, notes, and snippets.

@SamSaffron
SamSaffron / Ruby 2.7.4
Created Nov 3, 2021
Discourse Bench Perf
View Ruby 2.7.4
---
categories:
50: 55
75: 58
90: 62
99: 110
home:
50: 96
75: 102
90: 111
View gist:6533a364752b6aa63ab3e8c87a837f06
% bin/turbo_rspec
Using recorded test runtime
Setting up parallel test mode - starting Redis 9 on port 10009
Setting up parallel test mode - starting Redis 2 on port 10002
Setting up parallel test mode - starting Redis 1 on port 10001
Setting up parallel test mode - starting Redis 14 on port 10014
Setting up parallel test mode - starting Redis 6 on port 10006
Setting up parallel test mode - starting Redis 10 on port 10010
Setting up parallel test mode - starting Redis 5 on port 10005
Setting up parallel test mode - starting Redis 13 on port 10013
View test3.rb
require 'benchmark/ips'
numbers = (1..10000).to_a
numbers_as_string = "," + (1..10000).to_a.join(",") + ","
numbers_as_hash = {}
(1..10000).each {|n| numbers_as_hash[n] = true }
serialized_numbers = Marshal.dump(numbers)
serialized_string = Marshal.dump(numbers_as_string)
serialized_hash = Marshal.dump(numbers_as_hash)
View test2.rb
require 'benchmark/ips'
require 'json'
require 'oj'
count = 1
numbers_as_string_json = ("," + (1..count).to_a.join(",") + ",").to_json
numbers_json = (1..count).to_a.to_json
needle = 1000000
View test2.rb
require 'benchmark/ips'
require 'json'
require 'oj'
numbers_as_string_json = ("," + (1..10000).to_a.join(",") + ",").to_json
numbers_json = (1..10000).to_a.to_json
Benchmark.ips do |x|
View test.rb
require 'benchmark/ips'
numbers = (1..10000).to_a
numbers_as_string = "," + (1..10000).to_a.join(",") + ","
Benchmark.ips do |x|
x.report("binary search numbers") do |i|
while i > 0
View demo.rb
# frozen_string_literal: true
require_relative '../rerunner/rerunner.rb'
class Car
def self.all_blue!
puts "all blue called"
sleep 0.1
puts "all blue set"
@@all_blue = true
View yaml.rb
# frozen_string_literal: true
# tiny rerunner (I use this on local to rerun script)
require_relative '../rerunner/rerunner.rb'
require 'yaml'
require 'psych'
yaml = <<~YAML
# amazing YAML file
#
# hello
View test.py
from ruamel.yaml import YAML
import sys
example = """
# hello
test: "test\\ntest\\ntest" # a test
test2: hello.. #world
"""
rt_yaml=YAML(typ='rt')
View db.rake
# frozen_string_literal: true
# we should set the locale before the migration
task 'set_locale' do
begin
I18n.locale = (SiteSetting.default_locale || :en) rescue :en
rescue I18n::InvalidLocale
I18n.locale = :en
end
end