Created
December 4, 2017 18:49
-
-
Save payam-int/13c5c9670ed26f436a3348110d54dad8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.IOException; | |
import java.io.ObjectOutputStream; | |
import java.net.Socket; | |
/** | |
* @Author Payam Mohammadi ([email protected]) | |
*/ | |
public class SetSocketTimeoutPerformance { | |
public static void main(String[] args) throws IOException, InterruptedException { | |
String host = "localhost"; | |
int port = 8585; | |
Socket socket = new Socket(host, port); | |
long time = 0, t1, t2; | |
for (int i = 0; i < 1000000; i++) { | |
t1 = System.nanoTime(); | |
socket.setSoTimeout((int) (Math.random()*1000 + 500)); | |
t2 = System.nanoTime(); | |
time += t2-t1; | |
} | |
System.out.println(((double) (time / 1000000))/1000); | |
// 0.162s @ localhost | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment