public ParallelTest() {
    StopWatch watch = new StopWatch("Timer");
    List<Integer> numbersToSum = new ArrayList<Integer>();

    System.out.println("Preparing data...");
    for (int i = 0; i < 1_000_000; i++) {
      numbersToSum.add(i);
    }
    System.out.println("Data prepared");
    watch.start("Parallel sum");
    Long sum = numbersToSum.stream().parallel().map(it -> it.longValue()).reduce(0L, Long::sum);
    watch.stop();

    watch.start("Sequence sum");
    sum = numbersToSum.stream().map(it -> it.longValue()).reduce(0L, Long::sum);
    watch.stop();

    Long[] arrayOfLong = new Long[20_000_000];
    // prepare array
    Arrays.parallelSetAll(arrayOfLong, it -> ThreadLocalRandom.current().nextLong(100_000));

    // make a copy
    Long[] arrayOfLongCopy = Arrays.copyOf(arrayOfLong, arrayOfLong.length);

    // print array
    Arrays.stream(arrayOfLong).limit(10).forEach(it -> System.out.print(it + ", "));
    System.out.println();
    watch.start("Parallel sort");
    // sort array and print
    Arrays.parallelSort(arrayOfLong);
    watch.stop();
    Arrays.stream(arrayOfLong).limit(10).forEach(it -> System.out.print(it + ", "));
    System.out.println();
    watch.start("Seq sort");
    Arrays.sort(arrayOfLongCopy);
    watch.stop();
    Arrays.stream(arrayOfLongCopy).limit(10).forEach(it -> System.out.print(it + ", "));

    System.out.println(watch.prettyPrint());
  }
Esempio n. 2
0
  public static void main(String[] args) {
    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("AC-test.xml");
    IRuleEngine ruleEngine = ctx.getBean("ruleEngine", IRuleEngine.class);

    System.out.println(ruleEngine.getRulePackages());

    //		ruleEngine.execute("p2", "1");

    PremiumCalcBom bom = new PremiumCalcBom();
    bom.setInsuredSex("F");
    bom.setInsPeriodUnit("Y");
    bom.setInsPeriod("10");
    bom.setPayMode("T");
    bom.setAmount(10000.0);
    bom.setInsuredBirthday("1990-01-01");

    System.out.println("start");

    StopWatch sw = new StopWatch();
    sw.start();
    //		for (int j = 0; j < 10000; j++) {
    for (int i = 80; i < 90; i++) {
      bom.setInsuredBirthday("19" + i + "-01-01");
      int r = ruleEngine.execute("com.enci.ecp.bizprocess.product.rule.premiumcalc_00177000", bom);
      //			System.out.println(bom.getTotalPremium());
    }
    //		}
    sw.stop();
    System.out.println(sw.prettyPrint());
  }
 void report() {
   System.out.println(stopWatch.prettyPrint());
   for (StopWatch.TaskInfo taskInfo : stopWatch.getTaskInfo()) {
     String taskName = taskInfo.getTaskName();
     if (!taskName.startsWith("warmup")) {
       double nanosecs = taskInfo.getTimeMillis() * 1000000.0;
       double averagens = nanosecs / counts.get(taskName);
       System.out.println(taskName + ": avg time (ns) " + averagens);
     }
   }
 }
 @Around("methodsToBeProfiled()")
 public Object profile(ProceedingJoinPoint pjp) throws Throwable {
   StopWatch sw = new StopWatch(getClass().getSimpleName());
   try {
     sw.start(pjp.getSignature().getName());
     return pjp.proceed();
   } finally {
     sw.stop();
     System.out.println("############## Performance : " + sw.prettyPrint());
   }
 }
  @Override
  public Object invoke(MethodInvocation invocation) throws Throwable {
    final StopWatch stopWatch = new StopWatch(invocation.getMethod().toGenericString());
    stopWatch.start("invocation.proceed()");

    try {
      log.info(">>>>>>> START METHOD {} <<<<<<<<<", invocation.getMethod().toGenericString());
      return invocation.proceed();
    } finally {
      stopWatch.stop();
      log.info(stopWatch.prettyPrint());
      log.info(">>>>>>> END METHOD {} <<<<<<<<<", invocation.getMethod().toGenericString());
    }
  }
Esempio n. 6
0
  @RequestMapping(
      value = "/data/aum.json",
      method = RequestMethod.GET,
      produces = "application/json")
  @ResponseBody
  public String getAumData2Json() {
    StopWatch w = new StopWatch("Data");
    w.start("raw");

    List<JSONObject> records = getRecords(configFile, dataFile);

    w.stop();
    log.info(w.prettyPrint());

    w.start("json");

    String json = JSONValue.toJSONString(records, JSONStyle.NO_COMPRESS);

    w.stop();

    log.info(w.prettyPrint());

    return json;
  }
 @Around("execution(* es.rubenjgarcia.aop.Foo.*(..))")
 public Object measureMethod(ProceedingJoinPoint pjp) throws Throwable {
   StopWatch sw = new StopWatch();
   Object retVal;
   try {
     sw.start(pjp.getTarget() + "." + pjp.getSignature());
     retVal = pjp.proceed();
   } catch (Throwable e) {
     throw e;
   } finally {
     sw.stop();
     System.out.println(sw.prettyPrint());
   }
   return retVal;
 }
Esempio n. 8
0
  /** Used in the main UI - draws the server map by querying the timeslot by time. */
  @Override
  public ApplicationMap selectApplicationMap(
      Application sourceApplication, Range range, SearchOption searchOption) {
    if (sourceApplication == null) {
      throw new NullPointerException("sourceApplication must not be null");
    }
    if (range == null) {
      throw new NullPointerException("range must not be null");
    }
    logger.debug("SelectApplicationMap");

    StopWatch watch = new StopWatch("ApplicationMap");
    watch.start("ApplicationMap Hbase Io Fetch(Caller,Callee) Time");

    LinkSelector linkSelector =
        new BFSLinkSelector(
            this.mapStatisticsCallerDao,
            this.mapStatisticsCalleeDao,
            hostApplicationMapDao,
            serverMapDataFilter);
    LinkDataDuplexMap linkDataDuplexMap =
        linkSelector.select(sourceApplication, range, searchOption);
    watch.stop();

    watch.start("ApplicationMap MapBuilding(Response) Time");
    ApplicationMapBuilder builder = new ApplicationMapBuilder(range);
    ApplicationMap map = builder.build(linkDataDuplexMap, agentInfoService, this.mapResponseDao);
    if (map.getNodes().isEmpty()) {
      map = builder.build(sourceApplication, agentInfoService);
    }
    watch.stop();
    if (logger.isInfoEnabled()) {
      logger.info("ApplicationMap BuildTime: {}", watch.prettyPrint());
    }
    if (serverMapDataFilter != null) {
      map = serverMapDataFilter.dataFiltering(map);
    }

    return map;
  }