I use simple Jackson code to convert from my object to json String, but it really slow. It takes 70 milisecond to convert only one object as below in my machine. Did I do something wrong?
70 milliseconds to encode and send a little JSON message is implausible. There is little doubt in my mind that the real explanation is that the 70 millisecond measurement an artifact of the way that you benchmarked your code. Probably, you didn't allow for JVM warm-up effects.
So, yes, you did your benchmarking incorrectly. Probably. For more information on what you may have done wrong, see:
Now I found out three solutions for sending MyClass's instance over network: 1: use Jackson to convert into byte[] and send. 2: use built-in serialization to convert into byte[] and send. 3: convert MyClass's members into String, then into byte[] and send. Is there any other better solution ?
In theory (i.e. if you have enough skill, time and patience) the best performance can be achieved by encoding the data by hand into a byte buffer and sending that. But that is only theoretical.
If you are looking for practical solutions that are potentially faster than the alternatives you have tried, take a look at Google Protocol Buffers. They are reputed to be fast ...
But I suspect that you may have drawn the wrong conclusion from your (probably) poorly designed benchmark; see above. I strongly recommend you redo that before you look for faster alternatives.
70 milliseconds for one object, but when I try 1000 objects, it only takes 114 milliseconds, isn't it strange?
Actually, it is not at all strange when you take account of the way that the JVM works.
When the JVM starts, it loads your code and starts running it using the bytecode interpreter. After the code has been interpreted for a bit, the JVM runs the JIT compiler to produce optimized native code for the methods that are being called frequently. This compilation process takes a significant amount of time.
So when you are measuring the time taken to send one object, you are probably really measuring the time to send one object AND do a bunch of JIT compilation. But that JIT compilation work won't need to repeated. Net result - processing one object appears to takes a surprising long time, compared to 1000.
JIT compilation is one of the common JVM warmup effects that can distort a poorly written Java benchmark.