Skip to content

Instantly share code, notes, and snippets.

🌚

Alexander Popov AlexWayfer

🌚
Block or report user

Report or block AlexWayfer

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@AlexWayfer
AlexWayfer / benchmark.rb
Last active Apr 3, 2020
Benchmark example
View benchmark.rb
# frozen_string_literal: true
require 'bundler/setup'
Bundler.setup :system
require 'pry-byebug'
require 'benchmark'
require 'benchmark/ips'
require 'benchmark/memory'
@AlexWayfer
AlexWayfer / results.md
Created Feb 12, 2020
Const check performance
View results.md
# frozen_string_literal: true

# require 'pry-byebug'

require 'benchmark'
require 'benchmark/ips'
require 'benchmark/memory'
View .preload.rb
# frozen_string_literal: true
def db_migrations
return @db_migrations if defined?(@db_migrations)
puts "Request to DB from #{self.class} (#{object_id})"
@db_migrations = [3, 5]
end
@AlexWayfer
AlexWayfer / output
Created Sep 14, 2018
Ruby Transducers benchmark
View output
> ruby test.rb
I, [2018-09-14T05:14:28.929558 #30046] INFO -- : true
Warming up --------------------------------------
native 1.000 i/100ms
baseline 2.000 i/100ms
lazy 1.000 i/100ms
via_transduce 1.000 i/100ms
Calculating -------------------------------------
native 11.293 (± 0.0%) i/s - 57.000 in 5.054247s
baseline 21.711 (± 4.6%) i/s - 110.000 in 5.077083s
@AlexWayfer
AlexWayfer / fibonacci.rb
Created May 1, 2017
MRI Multi-threading
View fibonacci.rb
# frozen_string_literal: true
def fibonacci(n)
return n if n <= 1
fibonacci(n - 1) + fibonacci(n - 2)
end
def calculate(id: 1, n: 40)
start = Time.now
puts "Start ##{id}: #{start}"
@AlexWayfer
AlexWayfer / is_empty.rb
Created Nov 9, 2016
Checking of object empty
View is_empty.rb
class MyObject
attr_accessor :foo, :bar
def initialize(foo = nil, bar = nil)
self.foo = foo
self.bar = bar
end
def empty?
foo.nil? || foo.empty?
@AlexWayfer
AlexWayfer / including.rb
Last active Nov 7, 2016
Example for meta including
View including.rb
# Including neccessary modules from ./base/modules
Dir.glob(File.join 'base', 'modules', '*.rb').each do |mod|
require mod
basename = File.basename mod, '.*'
include const_get basename.split('_').map(&:capitalize).join
# With helpers:
# include basename.camelize.constantize
end
@AlexWayfer
AlexWayfer / alias_task.rake
Created Jun 23, 2016 — forked from raggi/alias_task.rake
A helper to alias a task in rake
View alias_task.rake
def alias_task(name, old_name)
t = Rake::Task[old_name]
desc t.full_comment if t.full_comment
task name, *t.arg_names do |_, args|
# values_at is broken on Rake::TaskArguments
args = t.arg_names.map { |a| args[a] }
t.invoke(*args)
end
end
You can’t perform that action at this time.