예제 #1
0
  @Test
  public void test_findDiscountPrices() {
    long time1 =
        Performance.getConsumedTime(
            () -> {
              List<String> discountPrices = Shop.getDiscountPricesSync(shops, "MaxBook 11");

              assertEquals(shops.size(), discountPrices.size());
            });

    long time2 =
        Performance.getConsumedTime(
            () -> {
              List<String> discountPrices = Shop.getDiscountPricesAsync(shops, "MaxBook 11");

              assertEquals(shops.size(), discountPrices.size());
            });

    System.out.println("getDiscountPrices Sync: " + time1);
    System.out.println("getDiscountPrices Async: " + time2);
  }
예제 #2
0
  @Test
  public void test_findPrices() {
    long time1 =
        Performance.getConsumedTime(
            () -> {
              List<String> priceTexts = Shop.findPricesSync(shops, "MacBook 11");
              assertEquals(shops.size(), priceTexts.size());
            });

    long time2 =
        Performance.getConsumedTime(
            () -> {
              List<String> priceTexts =
                  Shop.findPricesAsyncUsingParallelStream(shops, "MacBook 11");
              assertEquals(shops.size(), priceTexts.size());
            });

    long time3 =
        Performance.getConsumedTime(
            () -> {
              List<String> priceTexts =
                  Shop.findPricesAsyncUsingCompletableFuture1(shops, "MacBook 11");
              assertEquals(shops.size(), priceTexts.size());
            });

    long time4 =
        Performance.getConsumedTime(
            () -> {
              List<String> priceTexts =
                  Shop.findPricesAsyncUsingCompletableFuture(shops, "MacBook 11");
              assertEquals(shops.size(), priceTexts.size());
            });

    System.out.println("getPrices Sync : " + time1);
    System.out.println("getPrices Async Parallel Stream : " + time2);
    System.out.println("getPrices Async Completable Future: " + time3);
    System.out.println("getPrices Async Completable Future with Custom Executor: " + time4);
  }
예제 #3
0
  @Test
  public void test_supplyAllPrices() {
    long start = System.nanoTime();
    long time1 =
        Performance.getConsumedTime(
            () -> {
              Shop.supplyAllPrices(
                  shops,
                  "Mac Book 13",
                  (price) -> {
                    long diff = (System.nanoTime() - start) / 1000000;
                    System.out.println(price + " (discounted) done in " + diff);
                  });
            });

    System.out.println("supplyAllPrices time: " + time1);
  }
예제 #4
0
  @Test
  public void test_getPriceAsync() {

    long operationTime =
        Performance.getConsumedTime(
            () -> {
              Future<Double> futurePrice = s.getPriceAsync2("MacBook 11");

              try {
                double price = futurePrice.get();
                System.out.println("Price " + price);
              } catch (InterruptedException e) {
                e.printStackTrace();
              } catch (ExecutionException e) {
                throw new RuntimeException(e);
              }
            });

    System.out.println("Time: " + operationTime);
  }