package com.bee.tl.performance.lab;

import com.bee.tl.performance.Log;

public class NumberTest {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		new NumberTest().testAdd();

	}
	
	static Integer[] cache = new Integer[128];
	static {
		for(int i=0;i<cache.length;i++){
			cache[i] = new Integer(i);
		}
	}
	
	

	 void testAdd(){
		int loop = 10000*50000;
		Object a = 3;
		Object b = 22;
		
		
		Log.key1Start();
		for(int i=0;i<loop;i++){
			testAddPlan1(a,b);
		}
		Log.key1End();
		
		
		Log.key2Start();
		for(int i=0;i<loop;i++){
			testAddPlan2(a,b);
		}
		Log.key2End();
		
		Log.key3Start();
		for(int i=0;i<loop;i++){
			testAddPlan3(a,b);
		}
		Log.key3End();
		
		Log.display();
		
	}
	
	public Object testAddPlan1(Object a,Object b){
		int t = 1;
		switch(t){
		case 1:{
			 return Integer.valueOf(((Integer)a).intValue()+((Integer)b).intValue());
		}
		}
		return 0;
		
	}
	
	public Object testAddPlan2(Object a,Object b){
		int t = 1;
		switch(t){
		case 1:{
			 return ((Integer)a).intValue()+((Integer)b).intValue();
		}
		}
		return 0;
		
	}
	
	public Object testAddPlan3(Object a,Object b){
		int t = 1;
		switch(t){
		case 1:{
			
			 int c =((Integer)a).intValue()+((Integer)b).intValue();
			 if(c>0&&c<cache.length){
				 return cache[c];
			 }else{
				 return new Integer(c);
			 }
		}
		}
		return 0;
		
	}
	
	
	
	
	public int  getType(Object a,Object b){
		if( a instanceof Integer || b instanceof Integer){
			return 1;
		}else if(a instanceof Double || b instanceof Double){
			return 2;
		}else{
			return 3;
		}
	}
	
	
	
}

@@ -393,17 +393,16 @@
 000*5000
-0
 ;%0D%0A%09%09Obj
@@ -409,16 +409,18 @@
 ect a = 
+33
 3;%0D%0A%09%09Ob
@@ -429,16 +429,18 @@
 ct b = 2
+33
 2;%0D%0A%09%09%0D%0A
@@ -737,24 +737,122 @@
 End();%0D%0A%09%09%0D%0A
+%09%09Log.key4Start();%0D%0A%09%09for(int i=0;i%3Cloop;i++)%7B%0D%0A%09%09%09testAddPlan4(a,b);%0D%0A%09%09%7D%0D%0A%09%09Log.key4End();%0D%0A%09%09%0D%0A
 %09%09Log.displa
@@ -1169,16 +1169,28 @@
  return 
+new Integer(
 ((Intege
@@ -1224,24 +1224,25 @@
 ).intValue()
+)
 ;%0D%0A%09%09%7D%0D%0A%09%09%7D%0D
@@ -1355,16 +1355,200 @@
 se 1:%7B%0D%0A
+%09%09%09 return ((Integer)a).intValue()+((Integer)b).intValue();%0D%0A%09%09%7D%0D%0A%09%09%7D%0D%0A%09%09return 0;%0D%0A%09%09%0D%0A%09%7D%0D%0A%09%0D%0A%09public Object testAddPlan4(Object a,Object b)%7B%0D%0A%09%09int t = 1;%0D%0A%09%09switch(t)%7B%0D%0A%09%09case 1:%7B%0D%0A
 %09%09%09%0D%0A%09%09%09
@@ -1725,32 +1725,32 @@
 %09return 0;%0D%0A%09%09%0D%0A
-
 %09%7D%0D%0A%09%0D%0A%09%0D%0A%09%0D%0A%09%0D%0A
@@ -1745,24 +1745,27 @@
 %09%0D%0A%09%0D%0A%09%0D%0A%09%0D%0A
+%09%0D%0A
 %09public int 

测试自动装箱以及Integer cache的影响