" /> java - Pourquoi l'impression de B considérablement plus lent que l'impression "#" | 2022 codeprofesseur

java - Pourquoi l'impression de B considérablement plus lent que l'impression "#"

Mots clés : javaperformanceloopsfor-loopsystem.outjava

meilleur 4 Réponses java - Pourquoi l'impression de B considérablement plus lent que l'impression "#"

vote vote

92

for (int i = 0; i < 1000; i++) {     long t1 = System.nanoTime();     System.out.print("BBB......BBB"); \\<-contain 1000 "B"     long t2 = System.nanoTime();     System.out.println(t2-t1);     System.out.println(""); } 
BBB...31744 BBB...31744 BBB...31744 BBB...31744 BBB...226365807 BBB...31744 BBB...31744 BBB...31744 BBB...31744 BBB...226365807 . . . 
vote vote

85

Random r = new Random(); for (int i = 0; i < 1000; i++) {     for (int j = 0; j < 1000; j++) {         if(r.nextInt(4) == 0) {             System.out.print("O");         } else {             System.out.print("B");         }         if(j%100==0){               //Adding a line break in second loop                   System.out.println();         }                         }     System.out.println("");                 } 
vote vote

72

var arr = ['first'];  arr.push('second', 'third');  console.log(arr);
var arr = ['first'];  arr.push('second', 'third');  arr.push.apply(arr, ['forth', 'fifth']);  console.log(arr);
var arr = ['first'];  arr.push('second', 'third');    arr.push(...['fourth', 'fifth']);  console.log(arr) ;
vote vote

61

var array1 = [11, 32, 75]; var array2 = [99, 67, 34];  Array.prototype.push.apply(array1, array2); console.log(array1);

Questions similaires