lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 35037] - [PATCH] Some Field methods use Classcast check instead of instanceof which is slow
Date Tue, 24 May 2005 21:44:00 GMT
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG·
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=35037>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND·
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=35037





------- Additional Comments From whoschek@lbl.gov  2005-05-24 23:44 -------
I don't know what you were measuring but that's not the the case in any environment I've seen
since 
JDK 1.3, even with the client VM. To see for yourself try this, with and without cast() /
cast2(). 


	public static void main(String[] args) throws Exception {
		int iters = Integer.parseInt(args[0]); // e.g. 1000
		int runs = Integer.parseInt(args[1]);  // e.g. 3
		int sum = 0;
		Object[] arr = new Object[10000];
		Object obj = "xx";
		if (Boolean.valueOf(args[2]).booleanValue()) obj = new Integer(0);
		for (int i=0; i < arr.length; i++) arr[i] = obj;
		
		for (int run=0; run < runs; run++) {
			System.out.println("\nrun=" + run);
			long start = System.currentTimeMillis();
			for (int j=0; j < iters; j++) {
				for (int i=0; i < arr.length; i++) {
					sum += cast2(arr[i]).charAt(0);
//					sum += cast(arr[i]).charAt(0);
				}
			}
			long end = System.currentTimeMillis();
			System.out.println("secs = " + ((end-start) / 1000.0f));
		}
		System.out.println("checksum=" + sum);
	}
	
	private static String cast(Object x) {
		if (x instanceof String) return (String)x;
		return "yy";
	}
	
	private static String cast2(Object x) {
		try {return (String)x; } catch (ClassCastException e) { return "yy"; }
	}


-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

---------------------------------------------------------------------
To unsubscribe, e-mail: java-dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-dev-help@lucene.apache.org


Mime
View raw message