Skip to content

Instantly share code, notes, and snippets.

View tagomoris's full-sized avatar

Satoshi Tagomori tagomoris

View GitHub Profile
N=1_000
line = "a" * 200 + "\n"
body = line * 300
Benchmark.bm{|x|
x.report("splitonly") {
N.times{
buf = body.dup
lines = []
while !buf.empty?
lines << buf.slice!(0,201)
server_create(:title, proto: :tcp, port: @port, connection_callback: true) do |conn|
# on connection
source_addr = conn.addr
source_port = conn.port
conn.data do |data|
# on data
conn.write resp # ...
conn.disconnect
end
@tagomoris
tagomoris / name_error_or_nil.rb
Created November 7, 2016 09:54
variable not assigned by errors is nil.
def foo
raise "yay"
end
def hoge
tag = foo
rescue => e
{tag: tag, e: e}
end
# block and yield
[15] pry(main)> t = Time.now; 10_000_000.times{ myroot2{|t,r| t; r; 1} }; p(Time.now - t)
19.370526
=> 19.370526
# multi value return
[16] pry(main)> t = Time.now; 10_000_000.times{ myroot1{|t,r| t; r; 1} }; p(Time.now - t)
14.743976
=> 14.743976
@tagomoris
tagomoris / forward-protocol-spec-v1.md
Last active August 31, 2016 09:14
Fluentd Forward Protocol version 1 Draft

Fluentd Forward Protocol Specification (v1)

This is a protocol specification for Fluentd forward input/output plugins. This protocol is also used by fluent-logger software, and many other software in ecosystem (e.g., Docker logging driver for Fluentd).

This protocol version is v1. This spec is supported by Fluentd v0.14 (v0.14.5 and later), and v1 (in plan). Protocol version v0 is supported by v0.10 and v0.12, and protocol version v1 is compatible with v0 (All implementations which supports v1 also supports v0).

Changes

  • August 30, 2016: start to write this draft
class A
def foo
"a"
end
end
class B < A
def foo
v = super
"b#{v}"
@tagomoris
tagomoris / HOW_TO.md
Created May 27, 2016 07:56
Fluentd benchmark tests for v0.14.0 RC3

Instances

AWS EC2 c3.8xlarge / Ubuntu 14.04

Environment

Ruby 2.3.1 (rbenv + ruby-build)

# .bash_profile
require 'msgpack'
class MyObj
def initialize(sec=nil, nsec=nil)
t = Time.now
@sec = sec || t.sec
@nsec = nsec || t.nsec
end
def to_msgpack(io = nil)
MBA:~ tagomoris$ ruby objspace_test.rb
objspace_test.rb:14:in `block in <main>': can't convert Yay to Integer (Yay#to_int gives Yay) (TypeError)
from objspace_test.rb:12:in `each_object'
from objspace_test.rb:12:in `<main>'
MBA:~ tagomoris$ ruby -v
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin15]
@tagomoris
tagomoris / jruby_dies.rb
Created December 24, 2015 12:07
Both of jruby-1.7.x and jruby-9.x die with this script
require 'openssl'
cert = OpenSSL::X509::Certificate.new
puts cert.to_text
exit 0