Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Map.Entry;
- import Benchmark;
- import Benchmark.Operation;
- import Benchmark.Performance;
- public class Main {
- public static void main(String[] args) throws Exception {
- Operation o1 = new Operation() {
- @Override
- public void run() {
- int[] a = new int[] { 1, 2 };
- boolean b = a instanceof int[];
- }
- @Override
- public String getId() {
- return "a instanceof int[]";
- }
- };
- Operation o2 = new Operation() {
- @Override
- public void run() {
- int[] a = new int[] { 1, 2 };
- boolean b = a.getClass().isArray();
- }
- @Override
- public String getId() {
- return "a.getClass().isArray()";
- }
- };
- Operation o3 = new Operation() {
- @Override
- public void run() {
- int[] a = new int[] { 1, 2 };
- boolean b = a.getClass().getName().charAt(0) == '[';
- }
- @Override
- public String getId() {
- return "a.getClass().getName().charAt(0) == '['";
- }
- };
- Benchmark b = new Benchmark(o1, o2, o3);
- b.setNestedLoopIterations(5000000);
- b.setMainLoopIterations(100);
- b.run();
- for (Entry<String, Performance> e : b.getPerformances().entrySet()) {
- System.out.println("{" + e.getKey() + "} spends " + e.getValue());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement