FAQ
I quickly ported the Scala code to Java (Java code at the end of the post).
On my machine (Core i7-4600M, 2.90 GHz, quad-core, Windows 7) I get these
results:

Go 1.4.1:

encode: 1333333600, 3.4110
decode: 1000000000, 15.3430

Scala (JDK8):

encode: 1368421200, 13.783206397
decode: 1000000000, 26.121356501

Java (JDK8):

encode: 1368421200, 31.008432298
decode: 1000000000, 58.633304231


So Go performs remarkably better than Scala. Quite astonishing that Java is
so much slower than Scala. To me Go is doing really well compared to other
languages that also don't call C (admittedly, I don't exactly know what the
Java classes BASE64Encoder, BASE64Decoder are exactly doing).

-- H.

Java code:

mport sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;

import java.io.IOException;

/**
  * Created by plohmann on 13.04.2015.
  */
public class Base64 {

     public static void main(String[] args) throws IOException {

         BASE64Encoder enc = new sun.misc.BASE64Encoder();
         BASE64Decoder dec = new sun.misc.BASE64Decoder();

         int STR_SIZE = 10000000;
         int TRIES = 100;

         StringBuffer buffer = new StringBuffer();
         for (int i = 0; i < STR_SIZE; i++) {
             buffer.append("a");
         }
         String str = buffer.toString();
         String str2 = "";
         long t = System.nanoTime();
         long s = 0;

         for (int i = 0; i < TRIES; i++) {
             str2 = enc.encode(str.getBytes());
             s += str2.length();
         }

         System.out.println("encode: " + s + ", " + (System.nanoTime() - t)/1e9);
         s = 0;

         for (int i = 0; i < TRIES; i++) {
             byte[] str3 = dec.decodeBuffer(str2);
             s += str3.length;
         }

         System.out.println("decode: " + s + ", " + (System.nanoTime() - t)/1e9);
     }
}


--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

Discussion Posts

Previous

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 5 of 19 | next ›
Discussion Overview
groupgolang-nuts @
categoriesgo
postedApr 13, '15 at 1:36a
activeJun 22, '15 at 2:19p
posts19
users10
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase