Skip to content

Instantly share code, notes, and snippets.

View muga's full-sized avatar

Muga Nishizawa muga

View GitHub Profile
@muga
muga / gist:e566299fc9afdaa0511a8bb7804d5a7f
Created June 18, 2017 10:18
Implement key conversion with symbol in Java to reduce the count of objects passing between JRuby and Java
1,000 times Date._strptime('2001-02-03', '%Y-%m-%d')
user system total real
mri 2.4.1 0.000000 0.000000 0.070000 ( 0.086790)
jruby 9.1.9.0 0.000000 0.000000 8.020000 ( 3.789310)
jruby (master) 0.000000 0.000000 7.290000 ( 4.043696)
10,000 times Date._strptime('2001-02-03', '%Y-%m-%d')
user system total real
mri 2.4.1 0.000000 0.000000 0.090000 ( 0.142577)
jruby 9.1.9.0 0.000000 0.000000 12.450000 ( 7.671689)
@muga
muga / gist:b83262ed03009d2f765f8fd0c5319e54
Last active June 18, 2017 09:29
Cache RubyDateParser object in ThreadContext to reduce the count of passing objects between RubyObject and Java
1,000 times Date._strptime('2001-02-03', '%Y-%m-%d')
user system total real
mri 2.4.1 0.000000 0.000000 0.070000 ( 0.092492)
jruby 9.1.9.0 0.000000 0.000000 8.220000 ( 3.861129)
jruby (master) 0.000000 0.000000 7.130000 ( 3.671143)
10,000 times Date._strptime('2001-02-03', '%Y-%m-%d')
user system total real
mri 2.4.1 0.000000 0.000000 0.100000 ( 0.126605)
jruby 9.1.9.0 0.000000 0.000000 11.570000 ( 5.183052)
@muga
muga / gist:7b61e9284841c222275f9636dd9b7808
Last active June 18, 2017 09:11
Date._strptime performance compared by iterations
1,000 times Date._strptime('2001-02-03', '%Y-%m-%d')
user system total real
mri 2.4.1 0.000000 0.000000 0.110000 ( 0.261414)
jruby 9.1.9.0 0.000000 0.000000 8.840000 ( 4.920246)
jruby (master) 0.000000 0.000000 7.410000 ( 3.804355)
10,000 times Date._strptime('2001-02-03', '%Y-%m-%d')
user system total real
mri 2.4.1 0.000000 0.000000 0.080000 ( 0.082622)
@muga
muga / gist:eee8ebe794f959227a1887587e9dcc53
Created July 23, 2016 08:35
embulk-output-redis installation with embulk v0.8.10
$ .embulk/bin/embulk gem install embulk-output-redis --debug
2016-07-23 01:33:50.232 -0700: Embulk v0.8.10
NOTE: Debugging mode prints all exceptions even when rescued
Exception `LoadError' at org/jruby/RubyKernel.java:944 - no such file to load -- cgi/escape
Exception `Resolv::DNS::Config::NXDomain' at uri:classloader:/META-INF/jruby.home/lib/ruby/stdlib/resolv.rb:553 - _rubygems._tcp.api.rubygems.org
Exception `Resolv::DNS::Config::NXDomain' at uri:classloader:/META-INF/jruby.home/lib/ruby/stdlib/resolv.rb:553 - _rubygems._tcp.api.rubygems.org
Exception `Resolv::ResolvTimeout' at uri:classloader:/META-INF/jruby.home/lib/ruby/stdlib/resolv.rb:698 - Resolv::ResolvTimeout
Exception `Resolv::DNS::Config::NXDomain' at uri:classloader:/META-INF/jruby.home/lib/ruby/stdlib/resolv.rb:553 - _rubygems._tcp.api.rubygems.org.hsd1.ca.comcast.net
Exception `Resolv::DNS::Config::NXDomain' at uri:classloader:/META-INF/jruby.home/lib/ruby/stdlib/resolv.rb:553 - _rubygems._tcp.api.rubygems.org.hsd1.ca.comcast.net
Exception `
@muga
muga / gist:f36b753eafec465b1169bad448a6ec1e
Created July 23, 2016 08:35
embulk-output-bigquery installation with embulk v0.8.10
$ .embulk/bin/embulk gem install embulk-output-bigquery --debug
2016-07-23 01:31:59.082 -0700: Embulk v0.8.10
NOTE: Debugging mode prints all exceptions even when rescued
Exception `LoadError' at org/jruby/RubyKernel.java:944 - no such file to load -- cgi/escape
Exception `Resolv::DNS::Config::NXDomain' at uri:classloader:/META-INF/jruby.home/lib/ruby/stdlib/resolv.rb:553 - _rubygems._tcp.api.rubygems.org
Exception `Resolv::DNS::Config::NXDomain' at uri:classloader:/META-INF/jruby.home/lib/ruby/stdlib/resolv.rb:553 - _rubygems._tcp.api.rubygems.org
Exception `Resolv::DNS::Config::NXDomain' at uri:classloader:/META-INF/jruby.home/lib/ruby/stdlib/resolv.rb:553 - _rubygems._tcp.api.rubygems.org.hsd1.ca.comcast.net
Exception `Resolv::DNS::Config::NXDomain' at uri:classloader:/META-INF/jruby.home/lib/ruby/stdlib/resolv.rb:553 - _rubygems._tcp.api.rubygems.org.hsd1.ca.comcast.net
Exception `Resolv::ResolvError' at uri:classloader:/META-INF/jruby.home/lib/ruby/stdlib/resolv.rb:498 - DNS result has no information fo
@muga
muga / gist:b4126c40b40128c435a7
Created February 7, 2015 07:43
Compilation failed
$ gradle compileJava
:compileJava
/Users/muga/works/workspace/embulk-plugin-s3/src/main/java/org/embulk/plugin/s3/S3FileInputPlugin.java:21: error: cannot find symbol
import org.embulk.config.ConfigDiff;
^
symbol: class ConfigDiff
location: package org.embulk.config
/Users/muga/works/workspace/embulk-plugin-s3/src/main/java/org/embulk/plugin/s3/S3FileInputPlugin.java:54: error: cannot find symbol
import org.embulk.config.ConfigDiff;
^
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import org.msgpack.MessagePack;
import org.msgpack.packer.Packer;
import org.msgpack.type.MapValue;
import org.msgpack.type.Value;
org.apache.hadoop.hive.ql.Driver#compile(..)
...
ParseDriver pd = new ParseDriver();
// parser: parse sql commands with Hive lexer and parser. it converts into AST representation.
ASTNode tree = pd.parse(command, ctx);
...
// semantic analyzer: it analyzes ASTree semantically. that means it converts into block-base
// internal query representation.
BaseSemanticAnalyzer sem = SemanticAnalyzerFactory.get(conf, tree);
sem.analyze(tree, ctx);
import java.util.HashMap;
import java.util.Map;
import org.msgpack.MessagePack;
import org.msgpack.type.IntegerValue;
import org.msgpack.type.MapValue;
import org.msgpack.type.RawValue;
import org.msgpack.type.ValueFactory;
public class Sample {
@muga
muga / gist:4671001
Created January 30, 2013 05:48
sample with mockito
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
import org.junit.Test;
public class Sample {
static class Reader {
private String fileName;