View eat.exs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
list = Enum.to_list(1..10_000) | |
map_fun = fn(i) -> [i, i * i] end | |
Bunny.eat(%{ | |
"flat_map" => fn -> Enum.flat_map(list, map_fun) end, | |
"map.flatten" => fn -> list |> Enum.map(map_fun) |> List.flatten end | |
}) |
View my_user.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User < ApplicationRecord | |
attr_accessor :rollback | |
after_save :potentially_rollback | |
def potentially_rollback | |
raise ActiveRecord::Rollback if rollback | |
end | |
end |
View nested_transaction_requires_new.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
User.transaction do | |
User.create(name: 'Kotori') | |
User.transaction(requires_new: true) do | |
User.create(name: 'Nemu') | |
raise ActiveRecord::Rollback | |
end | |
end |
View nested_transactions.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
User.transaction do | |
User.create(name: 'Kotori') | |
User.transaction do | |
User.create(name: 'Nemu') | |
raise ActiveRecord::Rollback | |
end | |
end |
View why_comment.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def paint_control(event) | |
# some painting code | |
rescue => e | |
# Really important to rescue here. Failures that escape this method | |
# cause odd-ball hangs with no stacktraces. See #559 for an example. | |
puts "SWALLOWED PAINT EXCEPTION ON #{@obj} - go take care of it: " + e.to_s | |
puts 'Unfortunately we have to swallow it because it causes odd failures :(' | |
end |
View parameters.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# context, outlet, times, time per step, state, data | |
def pattern(c, o, t, l, s, d) | |
# ... | |
end |
View separating_comments.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# do one thing | |
... | |
... | |
... | |
... | |
# do another thing | |
... | |
... | |
... |
View benchee_hound.exs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ATTENTION: gotta start phantomjs via `phantomjs --wd` first.. | |
Application.ensure_all_started(:hound) | |
{:ok, server} = SimpleServer.start | |
Application.put_env(:hound, :app_host, "http://localhost") | |
Application.put_env(:hound, :app_port, SimpleServer.port(server)) | |
use Hound.Helpers |
View benchee_scenario.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Benchee.Benchmark.Scenario do | |
@moduledoc """ | |
A Scenario in Benchee is a particular case of a whole benchmarking suite. That | |
is the combination of a particular function to benchmark (`job_name` and | |
`function`) in combination with a specific input (`input_name` and `input`). | |
It then gathers all data measured for this particular combination during | |
`Benchee.Benchmark.measure/3` (`run_times` and `memory_usages`), | |
which are then used later in the process by `Benchee.Statistics` to compute | |
the relevant statistics (`run_time_statistics` and `memory_usage_statistics`). | |
""" |
View multiple_inputs.exs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
map_fun = fn(i) -> [i, i * i] end | |
Benchee.run(%{ | |
"flat_map" => fn(input) -> Enum.flat_map(input, map_fun) end, | |
"map.flatten" => fn(input) -> input |> Enum.map(map_fun) |> List.flatten end | |
}, | |
inputs: %{ | |
"Small" => Enum.to_list(1..1000), | |
"Bigger" => Enum.to_list(1..100_000) | |
}) |
NewerOlder