public static void main(String[] args) {
   int startTime, endTime;
   final int TIMES = 200_000;
   final int FACTOR = 1_000_000;
   int x;
   StringBuilder string1 = new StringBuilder("");
   StringBuilder string2 = new StringBuilder(TIMES * 4);
   LocalDateTime now;
   now = LocalDateTime.now();
   startTime = now.getNano();
   for (x = 0; x < TIMES; ++x) string1.append("Java");
   now = LocalDateTime.now();
   endTime = now.getNano();
   System.out.println(
       "Time with empty StringBuilder: " + ((endTime - startTime) / FACTOR + " milliseconds"));
   now = LocalDateTime.now();
   startTime = now.getNano();
   for (x = 0; x < TIMES; ++x) string2.append("Java");
   now = LocalDateTime.now();
   endTime = now.getNano();
   System.out.println(
       "Time with empty StringBuilder: " + ((endTime - startTime) / FACTOR + " milliseconds"));
 }
Пример #2
0
  @Test
  public void shouldPlayWithClocks() {
    Clock c1 = Clock.systemDefaultZone();
    print(c1.getZone() + "|" + c1.instant());

    StringBuilder builder = new StringBuilder();
    for (String zoneId : ZoneId.getAvailableZoneIds()) builder.append(zoneId).append(",");
    print(builder);

    ZoneId z1 = ZoneId.of("Australia/Tasmania");
    Clock c2 = c1.withZone(z1);
    print(c2.instant().atZone(z1));

    LocalDate d1 = LocalDate.now(c1);
    LocalDate d2 = LocalDate.now(c2);
    print(d1 + "|" + d2);
  }