/*
 * Copyright (c) 2007, Stephen Colebourne & Michael Nascimento Santos
 *
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 *  * Redistributions of source code must retain the above copyright notice,
 *    this list of conditions and the following disclaimer.
 *
 *  * Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution.
 *
 *  * Neither the name of JSR-310 nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
package javax.time;

import static javax.time.calendar.LocalTime.*;

import java.util.ArrayList;
import java.util.Collections;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.Random;

import javax.time.calendar.LocalTime;

/**
 * Test Performance.
 *
 * @author Stephen Colebourne
 */
public class Performance {

    /** Size. */
    private static final int SIZE = 100000;

    /**
     * Main.
     * @param args  the arguments
     */
    public static void main(String[] args) {
        LocalTime time = time(12, 30, 20);
        System.out.println(time);
        
        List<LocalTime> list = setup();
        sortList(list);
//        List<GregorianCalendar> list = setupGCal();
//        sortListGCal(list);
    }

    private static List<LocalTime> setup() {
        Random random = new Random(47658758756875687L);
        List<LocalTime> list = new ArrayList<LocalTime>(SIZE);
        long start = System.nanoTime();
        for (int i = 0; i < SIZE; i++) {
            LocalTime t = time(random.nextInt(24), random.nextInt(60), random.nextInt(60));
            list.add(t);
        }
        long end = System.nanoTime();
        System.out.println((end - start) + " ns");
        return list;
    }

    private static void sortList(List<LocalTime> list) {
        long start = System.nanoTime();
        Collections.sort(list);
        long end = System.nanoTime();
        System.out.println((end - start) + " ns");
    }

    private static List<GregorianCalendar> setupGCal() {
        Random random = new Random(47658758756875687L);
        List<GregorianCalendar> list = new ArrayList<GregorianCalendar>(SIZE);
        long start = System.nanoTime();
        for (int i = 0; i < SIZE; i++) {
            GregorianCalendar t = new GregorianCalendar(1970, 0, 1, random.nextInt(24), random.nextInt(60), random.nextInt(60));
            list.add(t);
        }
        long end = System.nanoTime();
        System.out.println((end - start) + " ns");
        return list;
    }

    private static void sortListGCal(List<GregorianCalendar> list) {
        long start = System.nanoTime();
        Collections.sort(list);
        long end = System.nanoTime();
        System.out.println((end - start) + " ns");
    }

}

@@ -19,16 +19,21 @@
 c) 2007,
+2008,
  Stephen
@@ -73,16 +73,16 @@
 Santos%0D%0A
-
  *%0D%0A * A
@@ -1734,24 +1734,52 @@
 ArrayList;%0D%0A
+import java.util.Calendar;%0D%0A
 import java.
@@ -2353,24 +2353,50 @@
 ist(list);%0D%0A
+        queryList(list);%0D%0A
 //        Li
@@ -2465,24 +2465,56 @@
 Cal(list);%0D%0A
+//        queryListGCal(list);%0D%0A
     %7D%0D%0A%0D%0A   
@@ -3236,32 +3236,512 @@
 ns%22);%0D%0A    %7D%0D%0A%0D%0A
+    private static void queryList(List%3CLocalTime%3E list) %7B%0D%0A        long total = 0;%0D%0A        long start = System.nanoTime();%0D%0A        for (LocalTime localTime : list) %7B%0D%0A            total += localTime.getHourOfDay().getValue();%0D%0A            total += localTime.getMinuteOfHour().getValue();%0D%0A            total += localTime.getSecondOfMinute().getValue();%0D%0A        %7D;%0D%0A        long end = System.nanoTime();%0D%0A        System.out.println((end - start) + %22 ns%22 + %22 %22 + total);%0D%0A    %7D%0D%0A%0D%0A
     private stat
@@ -4466,32 +4466,32 @@
 em.nanoTime();%0D%0A
-
         System.o
@@ -4535,11 +4535,473 @@
    %7D%0D%0A%0D%0A
+    private static void queryListGCal(List%3CGregorianCalendar%3E list) %7B%0D%0A        long total = 0;%0D%0A        long start = System.nanoTime();%0D%0A        for (GregorianCalendar gcal : list) %7B%0D%0A            total += gcal.get(Calendar.HOUR_OF_DAY);%0D%0A            total += gcal.get(Calendar.MINUTE);%0D%0A            total += gcal.get(Calendar.SECOND);%0D%0A        %7D;%0D%0A        long end = System.nanoTime();%0D%0A        System.out.println((end - start) + %22 ns%22 + %22 %22 + total);%0D%0A    %7D%0D%0A%0D%0A
 %7D%0D%0A

Add more performance comparisons