File: fibonacci-timing.rb

package info (click to toggle)
ruby-cabin 0.9.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 272 kB
  • sloc: ruby: 1,306; makefile: 12
file content (28 lines) | stat: -rw-r--r-- 730 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
require "rubygems"
require "cabin"
require "logger"

def fib(n)
  return 1 if n < 2
  return fib(n - 1) + fib(n - 2)
end

# Logging::... is something I'm implemented and experimenting with.
@logger = Cabin::Channel.new

# A logging channel can have any number of subscribers.
# Any subscriber is simply expected to respond to '<<' and take a single
# argument (the event)
# Special case of stdlib Logger instances that are wrapped smartly to 
# log JSON and call the right Logger method (Logger#info, etc).
@logger.subscribe(Logger.new(STDOUT))

# You can store arbitrary key-value pairs in the logging channel. 
# These are emitted with every event.

n = 35
@logger[:input] = n
@logger.time("fibonacci latency") do
  fib(n)
end