Go 1.5 Compile Speed

Go 1.5 has been released few days ago, today we will measure the compile speed of Go application. The source code for the measurement is around 36K lines (1.39 MB).

$ alias time
alias time='/usr/bin/time -f "\nCPU: %Us\tReal: %es\tRAM: %MKB"'

# Quad core i7 4700MQ, 16GB RAM, Linux 4.1.5 x86_64

# go version go1.3.3 linux/amd64
CPU: 4.39s Real: 2.54s RAM: 202944KB
CPU: 4.34s Real: 2.57s RAM: 202840KB
CPU: 4.47s Real: 2.60s RAM: 202844KB

# go version go1.4.2 linux/amd64
CPU: 4.23s Real: 2.39s RAM: 204656KB
CPU: 4.20s Real: 2.41s RAM: 204660KB
CPU: 4.71s Real: 2.81s RAM: 204624KB

# go version go1.5 linux/amd64
CPU: 17.09s Real: 6.35s RAM: 198416KB
CPU: 17.36s Real: 6.41s RAM: 198308KB
CPU: 17.35s Real: 6.21s RAM: 198000KB

The compile speed as stated on their mailing list, becomes significantly slower, I guess, I'll stick with 1.4 branch until 1.7 ready.


How to Install Go 1.5 on Windows 10

This tutorial will show you how to install Go 1.5 (but why?) on Windows 10. First of all you'll need to open your browser and go to http://golang.org

Click on the "Download Go" button, it will redirect to another page:

Click on the "Microsoft Windows" button, it will download an .msi file. After the download complete, run the file.

Click "Run": 

Click "Next", "Next", and so on until installed:

After finished, click the start menu, type "computer", right click on "This PC", choose "Properties":

Then choose "Advanced system settings", "Environment Variables..", click "New" on "user variables" panel.

Set the "GOPATH" to "%HOMEDRIVE%%HOMEPATH%\Documents\go" or anywhere else for your main go directory, something like this:

Click "OK" on all dialog, next, just open a "Command Prompt" window and create required directory, type 

go version
:: go version go1.5 windows/amd64
mkdir Documents\go\src
:: creating a directory, only required for the first time
cd Documents\go\src
:: change directory to %GOPATH%\src
notepad hello.go
:: edit a new source code

Create a new source code and type something like this:

package main
import `fmt`
func main() {
  fmt.Println( `Hello from Indonesia~ 1+1 =`, 1+1 )

Save, then go back to command prompt, type:

go run hello.go

A line will printed, and that's how you could install and run a example go program.
For more resources on how to learn programming in Go, please refer to the documentation (that can be viewed offline also, search for "GoDocServer" on the start menu.

There are some recommended IDE:
  1. IntelliJ IDEA with go-lang-idea-plugins
  2. LiteIDE (no-cost)
  3. Atom with go-plus (no-cost)
  4. Sublime Text with GoSublime
  5. Wide (no-cost)
  6. ZeusEdit
  7. KomodoIDE
  8. Eclipse PDE with GoClipse (no-cost)
That's it~ Btw how many "go" words in this article? 


Moving PostgreSQL Database to RAM

If you are software developer, sometimes you need to test your program faster. Normally the bottleneck of your program are in the database (writing to disk). You can increase the performance of your development/testing, by moving the database to the RAM if you have enough free RAM (>3GB). In this article, I will guide you to move your PostgreSQL database to RAM. First of all, you'll need to stop and disable the PostgreSQL, so the port won't conflict:

sudo systemctl stop postgresql
sudo systemctl disable postgresql

As we already know, /tmp folder on Linux mostly use tmpfs, that is a RAM file system. So if we create the database on the /tmp directory, it's on the RAM. What you'll need to do is create a script containing something like this:

#!/usr/bin/env bash
sudo killall postgres
# init directories
sudo rm -rf $src
mkdir -p $src
sudo chown postgres:postgres $src
sudo su - postgres <<EOF
initdb --locale en_CA.UTF-8 -E UTF8 -D '/tmp/data'
sed -i -- 's/max_connections = 100/max_connections = 1024/' /tmp/data/postgresql.conf
sed -i -- 's/#logging_collector = off/logging_collector = on/' /tmp/data/postgresql.conf
sed -i -- "s/#log_directory = 'pg_log'/log_directory = '\/tmp'/" /tmp/data/postgresql.conf
sed -i -- "s/#log_file_mode = 0600/log_file_mode = 0644/" /tmp/data/postgresql.conf
sed -i -- "s/#log_min_duration_statement = -1/log_min_duration_statement = 0/" /tmp/data/postgresql.conf
sed -i -- "s/#log_error_verbosity = default/log_error_verbosity = verbose/" /tmp/data/postgresql.conf
sed -i -- "s/#log_statement = 'none'/log_statement = 'all'/" /tmp/data/postgresql.conf
# sed -i -- "s///" /tmp/data/postgresql.conf
postgres -D /tmp/data &
echo sleep 2 seconds..
sleep 2
createuser xxx
createdb xxx
echo you can restore database now..

This script will erase all your database and create a new empty database on the RAM, that you can restore into later. This script will also create a log file that shows all queries that could help on the softwade development process. Lastly, to measure your PostgreSQL's data directory size in MB you can type this command:

$ sudo du -s -B 1M /tmp/data/
336     /tmp/data/

That's it, as a measurement, to restore a 137 MB database (about 300k records) in my PC normally it took about 17 seconds, when the database moved to RAM, it only took 5 seconds, so yes, it's a huge improvement.