All Downloads are FREE. Search and download functionalities are using the official Maven repository.

e.aic-expresso.aic-expresso.1.3.3.source-code.OverridingPerformanceTest Maven / Gradle / Ivy

Go to download

SRI International's AIC Symbolic Manipulation and Evaluation Library (for Java 1.8+)

The newest version!

public class OverridingPerformanceTest {

	interface Person {
		String live();
	}
	
	static class Parent implements Person {
		@Override
		public String live() {
			return "do what parents do";
		}
	}

	static class Child extends Parent {
		
		String name;
		boolean useParentAsRoleModel = true;
		
		public Child(String name, boolean useParentAsRoleModel) {
			super();
			this.name = name;
			this.useParentAsRoleModel = useParentAsRoleModel;
		}

		@Override
		public String live() {
			if (useParentAsRoleModel) {
				return super.live();
			}
			else {
				Parent anotherRoleModel = new Parent();
				return anotherRoleModel.live();
			}
		}
	}
	
	private static final long REPETITIONS = 10000000000L;

	public static void main(String[] args) {
		Child goodKid  = new Child("Good kid",  true);
		Child rebelKid = new Child("Rebel kid", false);

		for (Child kid : new Child[] {goodKid, rebelKid, goodKid}) {
			long start = System.currentTimeMillis();
			for (long i = 0; i != REPETITIONS; i++) {
				kid.live();
			}
			long end = System.currentTimeMillis();
			System.out.println(kid.name + " took: " + (end - start));
		}
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy