Skip to content

Instantly share code, notes, and snippets.

@Grab('org.gperfutils:gbench:0.4.2-groovy-2.3')
def r = benchmark {
def vs = [ 1, 2, 3, 4, 5, 6, 7, 8 ]
'Parallel Assignment' {
def (a, b, c, d, e, f, g, h) = vs
}
'Sequential Assignment' {
def a = vs[0]
def b = vs[1]
111111111111111111111111111111111111111111111111111111111111100001111111111111111111
111111111111111111111111111111111111111111111111111111111111000000011111111111111111
111111111111111111111111111111111111111111111111111111111110000000011111111111111111
111111111111111111111111111111111111111111111111111111111110000000001111111111100011
111111111111111111111111111111111111111111111111111111111110000000001111111110000001
111111111111111111111111111111111111111111111111111111111110000000001111111100000000
111111111111111111111111111111111111111111111111111111111110000000001111111000000000
111111111111111111111111111111111111111111111111110000111110000000001111111000000000
111111111111111111111111111111111111111111111111000000011110000000000111110000000000
111111111111111111111111111111111111111111111111000000011110000000000111110000000001
111111111111111111111111111111111111111111111111111111111111100001111111111111111111
111111111111111111111111111111111111111111111111111111111111000000011111111111111111
111111111111111111111111111111111111111111111111111111111110000000011111111111111111
111111111111111111111111111111111111111111111111111111111110000000001111111111100011
111111111111111111111111111111111111111111111111111111111110000000001111111110000001
111111111111111111111111111111111111111111111111111111111110000000001111111100000000
111111111111111111111111111111111111111111111111111111111110000000001111111000000000
111111111111111111111111111111111111111111111111110000111110000000001111111000000000
111111111111111111111111111111111111111111111111000000011110000000000111110000000000
111111111111111111111111111111111111111111111111000000011110000000000111110000000001
@masatonagai
masatonagai / byte_order.groovy
Last active December 26, 2015 18:09
Gets the host byte order in Groovy.
import static java.nio.ByteOrder.*
def bo = {
try {
// get the host byte order but not the jvm byte order
nativeOrder() == BIG_ENDIAN ?
'big endian' : 'little endian'
} catch (Error e) {
'unknown'
}
}()
class Greeter {
def greet(who) {
"Hi, $who"
}
}
def repos() {
"""https://oss.sonatype.org/${
project.version =~/.+SNAPSHOT/ ?
'content/repositories/snapshots'
: 'service/local/staging/deploy/maven2' }"""
}
project = [ version: '0.1.0' ]
assert repos() == 'https://oss.sonatype.org/service/local/staging/deploy/maven2'
# key bindings
set-option -g prefix C-t
unbind-key C-b
bind-key C-t send-prefix
bind t select-window -n
bind T select-window -p
bind s split-window -v
bind v split-window -h
@masatonagai
masatonagai / Fib.groovy
Created August 3, 2013 02:18
GProf 0.3.0 will be released soon!
@GrabResolver(name='snapshots', root='https://oss.sonatype.org/content/repositories/snapshots/')
@Grab('org.gperfutils:gprof:0.3.0-SNAPSHOT')
class Fib {
static def num(nth) {
nth < 2 ? nth : num(nth - 1) + num(nth - 2)
}
static void main(args) {
#!/bin/bash
# OS specific support (must be 'true' or 'false').
cygwin=false;
darwin=false;
solaris=false;
freebsd=false;
case "$(uname)" in
CYGWIN*)
cygwin=true
;;
@masatonagai
masatonagai / gbench_all.sh
Created May 3, 2013 03:45
Compare the performance of different versions of Groovy using GBench and GVM
#!/bin/bash
source ~/.gvm/bin/gvm-init.sh
versions=(1.7.11 1.8.9 2.0.8 2.1.3)
for version in ${versions[*]}
do
echo -n "Install groovy v${version}"
gvm install groovy $version
done