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 | |
}) |
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 |
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 |
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 |
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 |
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 |
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 | |
... | |
... | |
... |
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 |
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`). | |
""" |
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 + 1 end | |
Benchee.run %{ | |
"map tail-recursive with ++" => | |
fn -> MyMap.map_tco_concat(list, map_fun) end, | |
"map with TCO reverse" => | |
fn -> MyMap.map_tco(list, map_fun) end, | |
"stdlib map" => | |
fn -> Enum.map(list, map_fun) end, |
NewerOlder