/**
	 * 간단한 컬렉션 contains 성능테스트
	 *  -  https://dzone.com/articles/java-collection-performance
	 *
	 * @param args
	 */
	public static void main(String[] args) {

		long min = 999999999;
		long max = 0;
		for (int t = 0; t < 200; t++) {

			int cnt = 30000;
			LinkedHashSet<String> badwords = new LinkedHashSet<String>(); //min:500 ||  max:15200
			//ArrayList<String> badwords = new ArrayList<String>(); min:148100 ||  max:1110400

			//TreeSet<String> badwords = new TreeSet<String>(); //min:3000 ||  max:31000
			for (int i = 1; i <= cnt; i++) {
				badwords.add(String.valueOf(i));
			}

			long startMs = System.currentTimeMillis();

			long start = System.nanoTime();
			badwords.contains(String.valueOf(cnt));

			long end = System.nanoTime();
			long endMs = System.currentTimeMillis();

			long du = end - start;
			System.out.println(du);

			if (du > max) {
				max = du;
			}

			if (du < min) {
				min = du;
			}

			System.out.println("ms: " + (endMs - startMs));
		}

		System.out.println("\n\n");
		System.out.println("min:" + min + " ||  max:" + max);

	}

+ Recent posts