fork(2) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. long inicioCriando = System.currentTimeMillis();
  13.  
  14. new Thread(() -> {
  15. long inicio = System.currentTimeMillis();
  16.  
  17. for(int i=0;i<100000000;) {
  18. i++;
  19. }
  20.  
  21. long fim = System.currentTimeMillis();
  22.  
  23. System.out.println("Rodando lambda: " + (fim-inicio) / 1000f);
  24. }).start();
  25.  
  26. long fimCriando = System.currentTimeMillis();
  27.  
  28. System.out.println("Criando lambda: " + (fimCriando-inicioCriando) / 1000f);
  29.  
  30. inicioCriando = System.currentTimeMillis();
  31.  
  32. Runnable r = new Runnable(){
  33. public void run(){
  34. long inicio = System.currentTimeMillis();
  35.  
  36. for(int i=0;i<100000000;) {
  37. i++;
  38. }
  39.  
  40. long fim = System.currentTimeMillis();
  41.  
  42. System.out.println("Rodando Runnable anĂ´nimo: " + (fim-inicio) / 1000f);
  43. }
  44. };
  45.  
  46. new Thread(r).start();
  47.  
  48. fimCriando = System.currentTimeMillis();
  49.  
  50. System.out.println("Criando Runnable anĂ´nimo: " + (fimCriando-inicioCriando) / 1000f);
  51. }
  52. }
Success #stdin #stdout 0.12s 36476KB
stdin
Standard input is empty
stdout
Criando lambda: 0.009
Rodando lambda: 0.004
Criando Runnable anônimo: 0.001
Rodando Runnable anônimo: 0.003