这是所有编程语言的共同点吗?进行多次打印然后使用println似乎更快但将所有内容移动到字符串并且只是打印似乎最快.为什么?
编辑:例如,Java可以在不到一秒的时间内找到所有素数高达100万 – 但是打印然后在他们自己的println上全部打印可能需要几分钟!打印高达100亿小时!
EX:
package sieveoferatosthenes;
public class Main {
public static void main(String[] args) {
int upTo = 10000000;
boolean primes[] = new boolean[upTo];
for( int b = 0; b < upTo; b++ ){
primes[b] = true;
}
primes[0] = false;
primes[1] = false;
int testing = 1;
while( testing <= Math.sqrt(upTo)){
testing ++;
int testingWith = testing;
if( primes[testing] ){
while( testingWith < upTo ){
testingWith = testingWith + testing;
if ( testingWith >= upTo){
}
else{
primes[testingWith] = false;
}
}
}
}
for( int b = 2; b < upTo; b++){
if( primes[b] ){
System.out.println( b );
}
}
}
}