Beaucoup? Surtout la clé primaire Je pense qu'il y en a beaucoup int et long Ce sera une chaîne lors de la prise en sandwich de la communication API
La conversion est donc String.valueOf ou ʻObject.toString`?
package test;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
/**
 * test
 *
 * @author me
 *
 */
public class Test1 {
	/**
	 * main
	 * @param args
	 */
	public static void main(String[] args) {
		System.out.println("-------Commencer la mesure-------");
		Long start1 = System.currentTimeMillis();
		run1();
		Long end1 = System.currentTimeMillis();
		System.out.println("String.valueOf() : " + (end1 - start1) + "ms");
		Long start2 = System.currentTimeMillis();
		run2();
		Long end2 = System.currentTimeMillis();
		System.out.println("Object.toString() : " + (end2 - start2) + "ms");
		System.out.println("-------Fin de la mesure-------");
	}
	/**
	 * {@link String#valueOf()}
	 */
	private static void run1() {
		IntStream.range(0, 5000000).boxed().map(String::valueOf).collect(Collectors.toList());
	}
	/**
	 * {@link Object#toString()}
	 */
	private static void run2() {
		IntStream.range(0, 5000000).boxed().map(Object::toString).collect(Collectors.toList());
	}
}
-------Commencer la mesure-------
String.valueOf() : 2024ms
Object.toString() : 904ms
-------Fin de la mesure-------
Ouais, c'est différent ...
Eh bien, ʻObject.toString` ne peut pas être utilisé pour les types primitifs, et cela ressemble à ...
Au fait
package test;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
/**
 * test
 *
 * @author me
 *
 */
public class TestT {
	/**
	 * main
	 * @param args
	 */
	public static void main(String[] args) {
		System.out.println("-------Commencer la mesure-------");
		Long start1 = System.currentTimeMillis();
		run1();
		Long end1 = System.currentTimeMillis();
		System.out.println((end1 - start1) + "ms");
		System.out.println("-------Fin de la mesure-------");
	}
	/**
	 *Est-ce que c'est bon?
	 */
	private static void run1() {
		IntStream.range(0, 5000000).boxed().map(v -> v + "").collect(Collectors.toList());
	}
}
-------Commencer la mesure-------
3021ms
-------Fin de la mesure-------
Ce n'est pas bon w
Recommended Posts