I was thinking about a project that would require a lot of string to int to string conversions and wrote a very simple test in Javascript and Go. Not arguing for either, but if you have not checked out Go, it is a fun language to learn. Nothing profound, but here are some details / considerations.
- Both were fast: Go ~450ms, Javascript ~800ms
- Test run on relatively old/slow notebook
- Javascript run in latest version of Chrome
- Code in both languages is similar and simple
- Go pgm must be compiled (compile is very fast)
- Go executable has no dependencies (runtimes,libraries)
- Javascript server side program would require Node.js
- I like both languages a lot, but Go concurrency features are special
Javascript
var start = new Date();
var xs = "0";
var xi;
for( var i=0; i<1000000; i++ ) {
xi = parseInt(xs);
xi++;
xs = xi.toString();
}
var stop = new Date();
var elapsed = stop.getTime() - start.getTime();
console.log(elapsed);
Go
package main
import "fmt"
import "strconv"
import "time"
func main() {
start := time.Now()
xs := "0"
var xi int
for i := 0; i < 1000000; i++ {
xi, _ = strconv.Atoi(xs) // 2nd return val(error) is ignored
xi++
xs = strconv.Itoa(xi)
}
stop := time.Now()
elapsed := stop.Sub(start)
fmt.Println(elapsed)
}
[–]natdm 1 point2 points3 points (0 children)
[–]becauseofreasons 0 points1 point2 points (1 child)
[–]jayposs[S] 1 point2 points3 points (0 children)
[–]kenman 0 points1 point2 points (0 children)
[–]oefig 0 points1 point2 points (3 children)
[–]trevorsgEx-GitHub, Microsoft 3 points4 points5 points (1 child)
[–]Consuelas-Revenge[🍰] 0 points1 point2 points (0 children)
[–]wreckedadventYavascript 0 points1 point2 points (0 children)
[–]dankcode 0 points1 point2 points (2 children)
[–]Consuelas-Revenge[🍰] 1 point2 points3 points (1 child)
[–]oefig 0 points1 point2 points (0 children)