public static void timeFunction(Timed fn, int count) { long start = System.currentTimeMillis(); for (int i = 0; i < count; i++) { fn.apply(); } long totalTime = System.currentTimeMillis() - start; System.out.println("Total time: " + totalTime / 1000); }
/** * @param t the timed value * @return the partitions IDs, or null if the element either 1) does not satisfy the "condition" * 2) is not part of any one of the partitions. */ public List<Integer> evalPartitionsOn(Timed<T> t) { // check condition if (!condition.apply(t.getValue())) return null; // finds ids for each partition ArrayList<Integer> ids = new ArrayList<Integer>(); for (Named<Partition<Timed<T>>> p : partitions) { int id = p.getValue().toID(t); if (id == Partition.INVALID_ID) return null; ids.add(id); } return ids; }
/** * Adds a partition to the spec. If time is part of the partition criterion, use {@link * addTimedPartition} instead * * @param name the name of the partition * @param part the partition itself */ public void addPartition(String name, Partition<T> part) { partitions.add(Named.create(name, part.lift(Timed.<T>valueFunction()))); }
/** * Adds a time partition to the spec (not to be confused with {@link addTimedPartition}) * * @param name the name of the partition * @param part the partition itself */ public void addTimePartition(String name, Partition<Double> part) { partitions.add(Named.create(name, part.lift(Timed.<T>timeFunction()))); }