2016-11-14

Crystal Internal Benchmark (Nov 2016)

Update the snapshot of benchmark by Kostya. See the previous (April 2015) snapshot here.

  • gcc (Ubuntu 4.8.2-19ubuntu1) 4.8.2
  • Nim Compiler Version 0.14.0 (2016-06-06) [Linux: amd64]
  • Crystal 0.19.2 [d81c32c] (2016-09-16)
  • go version go1.7 linux/amd64
  • gccgo (Ubuntu 4.9.1-0ubuntu1) 4.9.1
  • DMD64 D Compiler v2.068.0
  • gdc (crosstool-NG crosstool-ng-1.20.0-232-gc746732 - 20150830-2.066.1-dadb5a3784) 5.2.0
  • LDC - the LLVM D compiler (0.15.2-beta1)
  • V8 version 3.29.62 (candidate)
  • rustc 1.11.0 (9b21dcd6a 2016-08-15)
  • Scala version 2.11.6 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_45)
  • Nodejs v7.0.0
  • PyPy 4.0.0 with GCC 4.8.4
  • topaz (ruby-1.9.3p125) (git rev b95c858) [x86_64-linux]
  • ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-linux]
  • Python 2.7.6 and  3.5.2
  • rubinius 2.2.10 (2.1.0 bf61ae2e 2014-06-27 JI) [x86_64-linux-gnu]
  • jruby 1.7.20 (1.9.3p551) 2015-05-04 3086e6a on Java HotSpot(TM) 64-Bit Server VM 1.8.0_45-b14 +jit [linux-amd64]
  • jruby 9.0.0.0.pre2 (2.2.2) 2015-04-28 2755ae0 Java HotSpot(TM) 64-Bit Server VM 25.45-b02 on 1.8.0_45-b14 +jit [linux-amd64]
  • Java version "1.8.0_45" Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)
  • julia version 0.4.3
  • clang version 3.5-1ubuntu1 (trunk) (based on LLVM 3.5)
  • Mono JIT compiler version 4.0.1 (tarball Tue May 12 15:39:23 UTC 2015)
  • rock 0.9.10-head codename sapphire, built on Wed Jul 1 20:09:58 2015
  • Felix version 15.04.03
  • Q KDB+ 3.3 2015.09.02 Copyright (C) 1993-2015 Kx Systems
  • perl 5, version 18, subversion 2 (v5.18.2) built for x86_64-linux-gnu-thread-multi
  • The Glorious Glasgow Haskell Compilation System, version 7.10.2
  • Tcl 8.6
  • jq version 1.3
  • Swift version 2.2-dev (LLVM ae2eb212e4, Clang ef4c02f431, Swift 634acb40a1)
  • Kotlin version 1.0.3 (JRE 1.8.0_45-b14)
  • PHP 7.0.9-1+deb.sury.org~trusty+1 (cli) ( NTS )
  • .Net Core 1.0.0-preview2-003121

Havlak loop finder
LanguageTime, sMemory, MiB
Crystal15.46443.2
Nim Gcc16.59484.3
Nim Clang16.91477.9
C++17.72174.5
D Ldc25.15214.9
D28.90418.2
Go31.26349.9
D Gdc31.79197.6
Scala32.18363.0
Go Gcc32.94365.7
C# Mono40.54270.0
Python Pypy45.51625.9
C# .Net Core61.38388.8
Python396.54724.0

Matrix multiplication
LanguageTime, sMemory, MiB
Julia Native Thr0.11148.3
Julia Native0.31175.8
D Mir GLAS0.3256.7
D Ldc2.0168.9
D2.3071.3
D Gdc2.3373.0
Python Numpy3.0865.3
Java3.50136.2
Scala3.62136.2
Kotlin3.62132.2
C3.6469.2
Nim Clang3.73142.3
Rust3.7476.9
Nim Gcc3.82146.0
Go3.8373.5
Crystal3.8573.9
Go Gcc3.9084.5
Swift4.48110.8
Javascript Node5.9588.3
Javascript V86.8781.5
Python Pypy7.68122.6
C# .Net Core10.8785.7
C# Mono15.1783.6
Julia20.98187.4
Ruby Topaz81.41206.2
Ruby338.4082.8
Python447.3974.0
Ruby JRuby416.12582.4
Ruby JRuby9k467.59608.3
Ruby Rbx591.70325.0
Perl666.46604.1
Tcl1066.66279.9

JSON parse
LanguageTime, sMemory, MiB
D Gdc Fast0.34226.7
C++ Rapid SAX0.721.0
Rust Pull0.78207.9
Rust Struct0.79232.5
C++ Gason0.83582.2
C++ Rapid0.94243.6
Java1.47621.2
Crystal Schema1.93331.2
Rust Value2.511967.0
Perl XS2.68888.4
Crystal3.001115.2
Javascript Node3.21863.7
Crystal Pull3.301.6
Nim Clang4.121089.6
Python3 ujson4.151303.2
Nim Gcc4.461090.1
Python Pypy4.811553.0
Python ujson5.071352.9
Q5.18684.0
Go5.21479.3
C++ LibJson5.492796.3
Clojure5.811148.5
Python35.821037.8
C# .Net Core6.31834.9
Php6.371502.0
Ruby YAJL8.231085.5
Haskell8.3170.5
Python9.851409.1
C# Mono10.57812.1
Julia11.892622.4
D12.421417.1
Ruby12.672013.9
JQ14.921714.5
Scala15.471415.8
C++ Boost16.442915.2
Ruby JRuby9K16.532050.5
Go Gcc17.64473.1
Ruby JRuby21.982761.1
D Gdc25.86926.1
D Ldc27.23919.6
Perl46.021635.4
Ruby Rbx67.134681.0

Base64 encode and decode

LanguageTime, sMemory, MiB
C aklomp SSSE30.9332.3
C1.8532.2
Crystal2.3085.0
D Gdc2.5233.3
Ruby2.73125.3
D Ldc3.1453.1
Perl XS3.6347.9
Rust3.6442.9
Ruby Rbx4.2930.7
Nim Gcc4.6252.7
Nim Clang4.7052.7
Julia4.41190.0
Javascript Node4.76551.5
C++ Openssl5.4565.2
Php6.3453.4
C# .Net Core6.52121.1
D7.1855.3
Tcl7.2066.0
Python Pypy7.32582.3
Python7.6252.6
Go8.0070.0
Python38.1354.5
C# Mono9.0171.7
Java9.06971.2
Kotlin9.75932.9
Scala10.69292.5
Ruby JRuby9K12.16530.6
Ruby JRuby12.65514.9
Perl33.3099.7
Go Gcc39.56185.5
Mandelbrot in Brainfuck
LanguageTime, sMemory, MiB
C++ Gcc20.491.7
Crystal23.131.5
D Ldc24.901.4
Rust25.194.9
D Gdc29.492.4
Nim Gcc31.042.7
Nim Clang37.392.9
Go Gcc37.5911.4
Kotlin40.7934.9
Scala58.51120.12
Java58.86423.9
D Dmd62.691.7
Javascript Node88.3418.6
Go102.852.2
Python Pypy126.4778.9
C# .Net Core142.3017.8
C# Mono147.6912.6
Ruby Topaz305.7938.8

Brainfuck interpreter
LanguageTime, sMemory, MiB
Kotlin1.7828.4
C++ Gcc1.941.0
D Ldc2.020.9
Rust2.494.9
Nim Gcc2.560.7
D Gdc3.051.4
Nim Clang3.090.8
Scala3.43120.12
Crystal3.461.3
Java4.03513.8
Go Gcc4.2010.0
D Dmd5.231.0
Go5.360.9
Javascript V86.537.9
Javascript Node7.3816.9
C# .Net Core16.0316.9
C# Mono19.8614.6
Python Pypy20.6477.9
Ruby Topaz59.5336.5
Ruby Rbx120.3832.3
Ruby Jruby129.75267.6
Ruby Jruby9k134.18286.8
Ruby181.447.2
Python314.794.9
Python3412.135.5

2016-11-02

Javascript Virtual DOM Framework Benchmark

Recently I found a framework benchmark for javascript (round4 2016-09-12), it shows a lot information. The fastest ranker are:

Framework Version Runtime Ratio (% slower than fastest) MB Start MB 1K rows
vanillajs
1 2.98 4.85
inferno 1.0.0-beta9 3 3.19 6.60
vanillajs-keyed
4 2.98 4.81
dio.js 3.0.5 4 3.19 7.09
domvm 2.0.0-beta 10 3.15 7.43
kivi 1.0.0-rc2 17 3.17 6.69

Also there are another benchmark (this have fewer framework, last result at this time):

Framework Init Time First Render Time Overall Time
kivi[adv] 1.0.0 2,185 25,795 527,703
Inferno 0.7.22 3,340 31,780 553,513
Imba 0.14.3 15,920 26,250 569,895
Bobril 4.38.0 3,430 26,255 682,847
Vidom 0.3.16 3,400 38,220 729,882
Maquette 2.3.3 1,955 27,410 733,165
Snabbdom 0.5.0 2,565 34,710 759,481
React 15.3.1 38,640 56,065 926,403
React-lite 0.15.6 6,345 40,725 1,105,627
Preact 5.4.0 2,550 53,585 1,150,506
Vanilla[innerHTML] 1.0.0 1,790 16,925 1,500,676
Deku 2.0.0-rc16 3,285 45,950 1,598,787
Mercury 14.1.0 2,840 41,325 2,115,253
yo-yo 1.2.2 1,825 21,835 2,295,505

Apparently there are a lot of them around the internet.
Of course you can build your own framework, here's the tips if you plan doing so.

2016-10-01

LXC Web Panel

As you (probably) already know, LXC (Linux Containers) or OpenVZ an operating-system-level virtualization is really faster than hardware virtualization, see the comparison. For those who hate CLI, you can use web interface called LXC Web Panel (for LXC 0.7 to 0.9, or newer fork 1.0+ here) to manage your containers:

wget https://lxc-webpanel.github.io/tools/install.sh -O - | sudo bash

This software only works on Ubuntu 12.04 or later. Despite of its performance, of course there are limitations, such as: you can only use host OS and architecture on guest. You can find more info on their website or this blog post.




So why LXC instead of Docker or Virtualization? because it's simpler :3 yes, both are different kind of animal, don't forget to check LXD and other alternatives too.



2016-07-14

ZSH is better BASH!

ZSH is better BASH, you should really change to newer and better shell.
Why it's better? it has better completion, support right prompt, see this presentation for more


Here's how to install it on ArchLinux:

pacman -S zsh zsh-completions
chsh -s `which zsh`
sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"

Oh-My-Zsh is package manager for zsh, you can change theme, add more aliases, for example:

plugins=(git git-extras redis-cli sudo systemd archlinux)

You can also install another theme, such as bullet-train:

mkdir $ZSH_CUSTOM/themes
cd $ZSH_CUSTOM/themes
aria2c "http://raw.github.com/caiogondim/bullet-train-oh-my-zsh-theme/master/bullet-train.zsh-theme"

Then set on ~/.zshrc:

BULLETTRAIN_DIR_EXTENDED=2
ZSH_THEME="bullet-train"

Remap Capslock to Backspace on Linux

Greatest idea IMHO from Colemak keyboard layout is replacing capslock with backspace key.


Here's how to do it in linux:

setxkbmap -option caps:backspace

But if you really need capslock, you can set pressing both shift key:

setxkbmap -option shift:both_capslock

These can be set on the ~/.xprofile file. For more xkeyboard tips, see this blog post.

On Mac OSX you can use Karabiner, for Windows, you look at this blog post.

Btw, have you heard about cheapest mechanical keyboard Nimxo K005?



2016-07-12

Keyboard with built-in Soundcard

I was looking for keyboard with built-in soundcard (not just passthrough), but the moderator deletes both my question and answers. Oh well, I post the updated results here now:

Cooler Master Storm Mech
+ Mechanical
+ White backlight
+ 1ms pooling rate
+ 1.5m cable
+ 553 x 267 x 43 mm
+ 1686 gr
+ 5 macro keys
+ USB 3
official review youtube


Thermaltake eSports Challenger Ultimate
+ Membrane
+ Full color backlight
+ 2ms pooling rate
+ 2m braided cable
+ 505 x 195 x 27 mm
+ Fan
+ 14x5 macro keys
+ 6 multimedia keys
official youtube


Logitech G510s
+ Membrane+ Full color backlight
+ 2ms pooling rate
+ 6 keys anti-ghosting
+ 2m cable
+ 557 x 215 x 31 mm
+ 1205 gr
+ Built-in LCD
+ UV Coated keys
+ 18 macro keys
+ 4 media keys
official youtube


Thermaltake eSports Poseidon Z Forged
+ Mechanical
+ Blue backlight
+ 1ms pooling rate
+ 104 keys anti-ghosting+ 1.8 m cable
+ 503 x 156 x 43 mm
+ 1474 gr
+ 10 macro keys
official review youtube


Thermaltake eSports Meka G-Unit
+ Mechanical
+ White backlight
+ 46 keys anti-ghosting
+ 1ms pooling rate
+ 554 x 271 x 70 mm
+ 1.8m braided cable+ 12 macro keys
+ 7 media keys
official youtube


What's the best? dunno guys XD never tried any of them.

2016-07-03

If Operating Systems ran The Airlines

Copied from https://telegram.me/programmerjokes

UNIX Airways 

Everyone brings one piece of the plane along when they come to the airport. They all go out on the runway and put the plane together piece by piece, arguing non-stop about what kind of plane they are supposed to be building.

Air DOS 

Everybody pushes the airplane until it glides, then they jump on and let the plane coast until it hits the ground again. Then they push again, jump on again, and so on...

Mac Airlines 

All the stewards, captains, baggage handlers, and ticket agents look and act exactly the same. Every time you ask questions about details, you are gently but firmly told that you don't need to know, don't want to know, and everything will be done for you without your ever having to know, so just shut up.

Windows Air 

The terminal is pretty and colourful, with friendly stewards, easy baggage check and boarding, and a smooth take-off. After about 10 minutes in the air, the plane explodes with no warning whatsoever.

Windows NT Air 

Just like Windows Air, but costs more, uses much bigger planes, and takes out all the other aircraft within a 40-mile radius when it explodes.

Windows XP Air 

You turn up at the airport,which is under contract to only allow XP Air planes. All the aircraft are identical, brightly coloured and three times as big as they need to be. The signs are huge and all point the same way. Whichever way you go, someone pops up dressed in a cloak and pointed hat insisting you follow him. Your luggage and clothes are taken off you and replaced with an XP Air suit and suitcase identical to everyone around you as this is included in the exorbitant ticket cost. The aircraft will not take off until you have signed a contract. The inflight entertainment promised turns out to be the same Mickey Mouse cartoon repeated over and over again. You have to phone your travel agent before you can have a meal or drink. You are searched regularly throughout the flight. If you go to the toilet twice or more you get charged for a new ticket. No matter what destination you booked you will always end up crash landing at Whistler in Canada.

Linux Air 

Disgruntled employees of all the other OS airlines decide to start their own airline. They build the planes, ticket counters, and pave the runways themselves. They charge a small fee to cover the cost of printing the ticket, but you can also download and print the ticket yourself.

When you board the plane, you are given a seat, four bolts, a wrench and a copy of the seat-HOWTO.html. Once settled, the fully adjustable seat is very comfortable, the plane leaves and arrives on time without a single problem, the in-flight meal is wonderful. You try to tell customers of the other airlines about the great trip, but all they can say is, "You had to do what with the seat?"

Example:
Sorry, this is the best analogy on the subject of linux, has been around for a long time, and is anonymous.

BTW, linux is the kernel, GNU/GPL software make up the rest of the OS and apps.  GNU/Linux is the way lawyers will say it in court.

2016-06-19

Flowchart to choose your programming language

Just now, I found a cool site to generate flowchart from source code (just like dot program):

(click for larger picture)

Anyway this just a joke, just like before (if programming language were religion/woman), may odds be in your favor..

Btw here's the code if you want to modify.. please use http://pastie.org if you want to do a long comment containing source code..

Choosing Programming language flowchart;
if(I really really care 
about runtime performance) {
  if(I am masochist..) {
    if(I like Mozilla..) {
      Use Rust;rust-lang.org
    } else {
      Use C++;cplusplus.com
    }
  } else if(I don't want 
  to learn something new..) {
    Use C;cprogramming.com
  } else if(I like long lines..) {
    Use Java;java.com
  } else if(I like FP?) {
    if(But I'm not masochist..) {
      Use Scala;scala-lang.org;
    } else if(I like parentheses..) {
      Use Clojure;clojure.org
    } else if(I like Microsoft) {
      Use FSharp;fsharp.org;
    } else {
      Use Haskell;haskell.org;
    }
  } else { 
    if(I like Microsoft..) {
      if(I hate C++) {
        if(My computer is ancient..) {
          Use VB6;
        } else {
          Use VB.NET;
        } 
        vbforums.com;
      } else {
        Use CSharp;csharp-station.com;
      }
    } else if(I like Facebook..) {
      Use Hack;hacklang.org;
    } else if(I like Apple..) {
      if(I'm a bit masochist..) {
        Use Objective-C;developer.apple.com;
      } else {
        Use Swift;swift-lang.org;
      }
    } else if(I like Google..) {
      if(But I also like java 
      and javascript..) {
        Use Dart;dartlang.org;
      } else { 
        Use Go;golang.org;
      }
    } else {
      // you can also use Lazarus
      // lazarus.freepascal.org
      Use Delphi;embarcadero.com;
    }
  } 
} else {
  if(I don't want to install a thing..) {
    if(I use linux, mac, or win 10) {
      Use Bash;bash-hackers.org;
    } else {
      Use Javascript;javascript.com;
    }
  } else if(I love spaghetti..) {
    if(I don't care about my future..) {
      // Most likely you will be killed by maintainer that reads your code..
      Use Perl;perl.org;
    } else {
      Use PHP;php.net;
    }
  } else if(I want to make game mods..) {
    Use Lua;lua.org;
  } else if(I like indentations..) {
    Use Python;python.org;
  } else {
    Use Ruby;ruby-lang.org;
  }
}

Aww snaps, I forgot to add Elixir, Julia, and Crystal  -_- oh well.. maybe sometime in the future.

2016-06-11

EasyEngine: WordPress made easy

So, newbies out there, for those that have a root server access or VPS, and you want to create a blog. There is a tool called EasyEngine that could help you (automate) setup Nginx (not Apache), PHP (or PHP7/HHVM), MariaDB/MySQL database, Postfix mail transfer agent, WordPress, WP Super Cache (or W3 Total Cache, Nginx Cache, WP Redis) on Ubuntu or Debian operating system.

There's a lot more it can offer:

How to install EasyEngine?

wget -qO ee rt.cx/ee && sudo bash ee

What's we must use this? it saves time (automated install, automatic update), best practice (Nginx instead of Apache, HHVM/PHP7 instead of PHP5, caching), configuration backup (using Git)


For more information you can visit their website https://easyengine.io/

But wait kiz, you hate PHP right? why you endorse this?
at least this IS far better than poor performance/neglected/insecure/lousy crap configuration/choice that I always see in the past.

2016-06-05

Go is Programming Language for The Future

Well, I like Go so much, Here's some reason why Go is the language for the future:

1. low learning curve. syntax similar to C, but it's simplified, high readability, standardized code-formatting, almost no syntax changes from older version to newer version, has compact language specification for whole language (only 79 A4 pages) compared to:
2. it performs near equal to Java
3. fast compile, especially for big project

4. concurrency at language level, it's no doubt that concurrency is the trend (processor manufacturer now tend to adding more cores)

5. garbage collected, safe-pointer, contrast to manual memory management that can lead to buggy code (eg. memory leaks, buffer overflow attacks)

6. built-in utf8 string and maps (associative array), as other newer programming language also done (the Go programming language creator also the one that wrote utf8)

7. big company support (Google), other companies that have been using Go: Dropbox, Twitter, SoundCloud, etc, this leads to future job vacancy.


8. small memory footprint (unlike Java, that everything has 8-12 bytes overhead)

9. built-in package management, it's easy to distribute libraries, leads to many contribution.

10. simple cross compilation

11. autocomplete daemon, this leads to many editor/IDE support

12. built-in testing support (for TDD/BDD)

There's many other things that I personally like from Go:
  • variable initial value always zeroed
  • limited set of operator (no frustration when other people use too many operator with confusing precedence)
  • no generics XD yes, I found C++'s template error message really painful, but templates are quite useful when writing generic data structures
  • letter case visibility
  • no function overloading
  • statically linked
  • no circular dependency
  • no warnings, just errors
I bet Go will become really popular in 2020 (at least until full-featured Swift comes to Linux and Windows). Hopefully there would be Go that compiles to WebAssembly :3



Real Reason to use newer Go 1.5+: Cross Compile

As you already know, that compiling in Golang becomes slower since 1.5+, then why we must use the newer? there's no incompatible syntax changes right? See the graph below for the compile duration ratio:


There's some you must consider when using older Go version (<1.4.3):
  1. Broken libraries, some libraries (such as fasthttp) doesn't support older version of Go (<1.5), because there are changes on standard libraries, for example there's no bytes.LastIndexByte, bufio.Reader.Discard,  time.Time.AppendFormat, etc on older version of go standard library)
  2. Slower GC (see Go 1.6 latest low latency garbage collector, it's even less than 21ms)
  3. Bigger binary produced (but see goupx)
  4. Slower runtime performance (but it's already fast compared to another language)
  5. No Vendoring (see no more dependency hell)
  6. And lastly, no Cross Compiling!
Did you know that since Go 1.5 you can build other platform's binary?

$ go build
-rwxr-xr-x   1 asd  staff  11261296 Jun  5 19:41 PUPS
PUPS: Mach-O 64-bit executable x86_64

$ env GOOS=linux GOARCH=amd64 go build
-rwxr-xr-x   1 asd  staff  9232191 Jun  5 19:42 PUPS
PUPS: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, not stripped

$ env GOOS=windows GOARCH=386 go build
-rwxr-xr-x   1 asd  staff  8048640 Jun  5 19:42 PUPS.exe
PUPS.exe: PE32 executable for MS Windows (console) Intel 80386 32-bit

This feature is really useful especially when your server is Linux, but you develop in Mac :3
Or when you want to create a cross-platform games/apps.

Solution for golang Slow Compile

I think this need more exposure, http://dev.pawelsz.eu/2015/09/slow-go-compilation.html show that slow compilation source, by using -x flag. This also related to my previous answer on stackoverflow http://stackoverflow.com/a/26752149/1620210 a real slowdown that happened after upgrading or downgrading to newer version of golang. Fortunately, there's a quickfix for that:

First of all if you are using go 1.7, you'll need to change the ownership of your GOROOT's pkg directory:

[ `ls -ld $GOROOT/pkg | awk '{print $3}'` != `whoami` ] && sudo chown -Rv `whoami` $GOROOT/pkg

Then if you are upgrading or downgrading, you'll need to remove the GOPATH's pkg directory, there's the bash snippet to check if gitlab.com/kokizzu/gokil library was precompiled with different golang version than installed:

PKG_OS_ARCH=`go version | cut -d ' ' -f 4 | tr '/' '_'`
[ `strings $GOPATH/pkg/$PKG_OS_ARCH/gitlab.com/kokizzu/gokil/A.a | grep 'go object' | head -n 1 | cut -f 5 -d ' '` != `go version | cut -f 3 -d ' '` ] && rm -rf $GOPATH/pkg

This last part stolen from the blog above, the real script that makes the next compile runs faster:

go list -f '{{.Deps}}' ./... | tr "[" " " | tr "]" " " | \
  xargs go list -f '{{if not .Standard}}{{.ImportPath}}{{end}}' | \
  xargs go install -a

Alternatively, you can use

go build -i

The last 2 commands above looks for all dependencies and recompile/preinstall them, it's better than I expected, normally it took about 15 seconds to recompile on go1.6.2.

# go 1.4.3
[gin] Build Successful in 1802.47 ms
[gin] Build Successful in 2854.65 ms
[gin] Build Successful in 2325.35 ms

# go 1.6.2
[gin] Build Successful in 5673.43 ms
[gin] Build Successful in 8081.75 ms
[gin] Build Successful in 6867.12 ms

# go 1.7b1
[gin] Build Successful in 2579.98 ms
[gin] Build Successful in 3649.08 ms
[gin] Build Successful in 4182.04 ms
[gin] Build Successful in 3881.66 ms
[gin] Build Successful in 3722.20 ms
[gin] Build Successful in 2785.84 ms
[gin] Build Successful in 2981.62 ms
[gin] Build Successful in 3793.66 ms
[gin] Build Successful in 4458.86 ms
[gin] Build Successful in 4376.60 ms

Anyway I still stick with go1.4.3 since it has the fastest compile, it makes our edit-compile-test cycle faster.

2016-05-26

Iris Web Framework

Shock! That was what I feel when see Iris benchmark '__'), after looking at the code, ah no wonder, it uses fastest router (fasthttp), that uses almost zero allocation per request.

These graphs stolen from SmallNest's go framework benchmark.









As usual, static request means nothing, dynamic request that uses database are the real bottleneck :3
Btw Iris has book for those who are interested. For those who doesn't need full framework, you can use the fasthttprouter.

EDIT: before you use Iris because of performance, see links on the comments below: this by julienschmidt (one that create httprouter) and this by dlsniper (one that initialize go-lang-idea-plugin project).

 What's the alternative? you can use valyala's FastHttp (only router), Arteugo, or Fiber (full framework, really similar to ExpressJS)

2016-04-19

Remap Keyboard Shortcut on Mac OSX

Recently I bought a secondhand Macbook Pro, since it's sold in a really-really good price. This is my first time experiencing Mac OSX, and my experience has been quite good, almost everything is there and easy as easy as yaourt+better automation (called brew), better UI than Windows, and I never feel any lag (maybe because it's SSD). All great, except, the shortcut keys, it's quite weird to have Fn key on the left of Ctrl key (just like most Lenovo laptops), also command key that replaces almost every normal shortcut on Windows and Linux.

First few days, using the shortcuts, I quite dissatisfied until I found about Karabiner! With that app, I could remap every keyboard shortcuts that I like so it becomes similar to Linux and Windows settings.


First thing I've done is switch Ctrl and Fn and vice versa. For all other shortcut, I edit the private.xml to match my preferred shortcut to Mac's shortcut. These are the content of the file:

<?xml version="1.0"?>
<root>
    <appdef>
        <appname>ITERM2</appname>
        <equal>com.googlecode.iterm2</equal>
    </appdef>
    <appdef>
        <appname>INTELLIJ</appname>
        <equal>com.jetbrains.intellij</equal>
    </appdef>
    <item>
        <name>Command-Q to Control-C</name>
        <appendix>Cmd-Q to Ctrl-C for iTerm2</appendix>
        <identifier>CQ2CC</identifier>
        <only>ITERM2</only>
        <autogen>
            __KeyToKey__
            KeyCode::Q, ModifierFlag::COMMAND_L,
            KeyCode::C, ModifierFlag::CONTROL_L
        </autogen>
    </item>
    <item>
        <name>Control to Alt</name>
        <appendix>Ctrl to Alt (Left/Right/Backspace)</appendix>
        <identifier>C2A</identifier>
        <not>INTELLIJ</not>
        <autogen>
            __KeyToKey__
            KeyCode::DELETE, ModifierFlag::CONTROL_L,
            KeyCode::DELETE, ModifierFlag::OPTION_L
        </autogen>
        <autogen>
            __KeyToKey__
            KeyCode::CURSOR_LEFT, ModifierFlag::CONTROL_L,
            KeyCode::CURSOR_LEFT, ModifierFlag::OPTION_L
        </autogen>
        <autogen>
            __KeyToKey__
            KeyCode::CURSOR_RIGHT, ModifierFlag::CONTROL_L,
            KeyCode::CURSOR_RIGHT, ModifierFlag::OPTION_L
        </autogen>
        <autogen>
            __KeyToKey__
            KeyCode::CURSOR_LEFT, ModifierFlag::CONTROL_L | ModifierFlag::SHIFT_L,
            KeyCode::CURSOR_LEFT, ModifierFlag::OPTION_L | ModifierFlag::SHIFT_L
        </autogen>
        <autogen>
            __KeyToKey__
            KeyCode::CURSOR_RIGHT, ModifierFlag::CONTROL_L | ModifierFlag::SHIFT_L,
            KeyCode::CURSOR_RIGHT, ModifierFlag::OPTION_L | ModifierFlag::SHIFT_L
        </autogen>
    </item>
    <item>
        <name>Control to Command</name>
        <appendix>Ctrl to Cmd (A/C/F/R/S/T/V/W/X/Z)</appendix>
        <identifier>C2C</identifier>
        <autogen>
            __KeyToKey__
            KeyCode::A, ModifierFlag::CONTROL_L,
            KeyCode::A, ModifierFlag::COMMAND_L
        </autogen>
        <autogen>
            __KeyToKey__
            KeyCode::C, ModifierFlag::CONTROL_L,
            KeyCode::C, ModifierFlag::COMMAND_L
        </autogen>
        <autogen>
            __KeyToKey__
            KeyCode::F, ModifierFlag::CONTROL_L,
            KeyCode::F, ModifierFlag::COMMAND_L
        </autogen>
        <autogen>
            __KeyToKey__
            KeyCode::L, ModifierFlag::CONTROL_L,
            KeyCode::L, ModifierFlag::COMMAND_L
        </autogen>
        <autogen>
            __KeyToKey__
            KeyCode::R, ModifierFlag::CONTROL_L,
            KeyCode::R, ModifierFlag::COMMAND_L
        </autogen>
        <autogen>
            __KeyToKey__
            KeyCode::S, ModifierFlag::CONTROL_L,
            KeyCode::S, ModifierFlag::COMMAND_L
        </autogen>
        <autogen>
            __KeyToKey__
            KeyCode::T, ModifierFlag::CONTROL_L,
            KeyCode::T, ModifierFlag::COMMAND_L
        </autogen>
        <autogen>
            __KeyToKey__
            KeyCode::V, ModifierFlag::CONTROL_L,
            KeyCode::V, ModifierFlag::COMMAND_L
        </autogen>
        <autogen>
            __KeyToKey__
            KeyCode::W, ModifierFlag::CONTROL_L,
            KeyCode::W, ModifierFlag::COMMAND_L
        </autogen>
        <autogen>
            __KeyToKey__
            KeyCode::X, ModifierFlag::CONTROL_L,
            KeyCode::X, ModifierFlag::COMMAND_L
        </autogen>
        <autogen>
            __KeyToKey__
            KeyCode::Z, ModifierFlag::CONTROL_L,
            KeyCode::Z, ModifierFlag::COMMAND_L
        </autogen>
    </item>
</root>

Keyboard map above will trigger most of mac shortcut, but using Ctrl key instead of Cmd key:

  • Cmd-Q will trigger Ctrl-C (exit current program) on iTerm2
  • Ctrl-Left/Right: skip word
  • Ctrl-Shift-Left/Right: select word
  • Ctrl-Backspace: delete 1 word
  • Ctrl-A: select all
  • Ctrl-C: copy
  • Ctrl-F: find
  • Ctrl-L: location
  • Ctrl-R: refresh
  • Ctrl-S: save
  • Ctrl-T: new tab
  • Ctrl-V: paste
  • Ctrl-W: close tab
  • Ctrl-X: cut
  • Ctrl-Z: undo
I didn't put some other shortcuts that I didn't use (mostly because it's can be configured on the IDE/TextEditor) or just because it's already works well, for example Ctrl-Tab for switching tab, Ctrl-D for logout, and so on. If you want to learn more, you can read the reference here.

2016-03-09

Lightweight Go IDE (with Debugging support)

Today I found that Visual Studio Code by Microsoft is quite charming, it based on Electron, library that being used to make Atom Editor (and Nuclide by Facebook). It loads fast, really fast. In ArchLinux or Manjaro, you can install it using this command:

yaourt -S visual-studio-code

After installing, type Ctrl+Shift+P, Install Extension, choose Go (Rich Go bla bla..). And yes, it requires internet connection.

Then install the tools required:

go get -u -v github.com/nsf/gocode
go get -u -v github.com/rogpeppe/godef
go get -u -v github.com/golang/lint/golint
go get -u -v github.com/lukehoban/go-find-references
go get -u -v github.com/lukehoban/go-outline
go get -u -v sourcegraph.com/sqs/goreturns
go get -u -v golang.org/x/tools/cmd/gorename
go get -u -v github.com/tpng/gopkgs
go get -u -v github.com/newhook/go-symbols

For debugging, install delve (it requires Go 1.5 or newer).

The import bulb will show if a package not yet imported:

The autocomplete just works as expected:

Argument tooltip (parameter info) shown correctly:

Jump to definition works (Ctrl+Click):

I believe this is better alternative (for now) than Atom, Brackets, LightTable, and LimeText (incomplete SublimeText implementation).