Created
July 26, 2011 22:38
-
-
Save cerealcable/1108260 to your computer and use it in GitHub Desktop.
Mutator Test Class
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package testapp; | |
| public class Main { | |
| public static void main(String[] args) { | |
| MyClass o = new MyClass(1243.91); | |
| Long start1 = System.nanoTime(); | |
| for(int i = 0; i < 10000; i++) { | |
| Double value = o.getValue(); | |
| } | |
| Long end1 = System.nanoTime(); | |
| Long start2 = System.nanoTime(); | |
| for(int i = 0; i < 10000; i++) { | |
| Double value = o.value; | |
| } | |
| Long end2 = System.nanoTime(); | |
| Long start3 = System.nanoTime(); | |
| for(int i = 0; i < 10000; i++) { | |
| o.setValue(22.22); | |
| } | |
| Long end3 = System.nanoTime(); | |
| Long start4 = System.nanoTime(); | |
| for(int i = 0; i < 10000; i++) { | |
| o.value = 22.22; | |
| } | |
| Long end4 = System.nanoTime(); | |
| Long time1 = end1 - start1; | |
| System.out.println("Access using method took " + time1); | |
| Long time2 = end2 - start2; | |
| System.out.println("Access using direct took " + time2); | |
| Long time3 = end3 - start3; | |
| System.out.println("Mutator using method took " + time3); | |
| Long time4 = end3 - start3; | |
| System.out.println("Mutator using direct took " + time3); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package testapp; | |
| public class MyClass { | |
| public Double value; | |
| public MyClass() { | |
| value = 0.0; | |
| } | |
| public MyClass(Double value) { | |
| this.value = value; | |
| } | |
| public Double getValue() { | |
| return value; | |
| } | |
| public void setValue(Double value) { | |
| this.value = value; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment