001/**
002 * Logback: the reliable, generic, fast and flexible logging framework.
003 * Copyright (C) 1999-2015, QOS.ch. All rights reserved.
004 *
005 * This program and the accompanying materials are dual-licensed under
006 * either the terms of the Eclipse Public License v1.0 as published by
007 * the Eclipse Foundation
008 *
009 *   or (per the licensee's choosing)
010 *
011 * under the terms of the GNU Lesser General Public License version 2.1
012 * as published by the Free Software Foundation.
013 */
014package ch.qos.logback.classic.issue.lbclassic36;
015
016import ch.qos.logback.classic.issue.lbclassic36.SelectiveDateFormattingRunnable.FormattingModel;
017import ch.qos.logback.core.contention.ThreadedThroughputCalculator;
018
019/**
020 * Measure the threaded throughtput of date formatting operations
021 * 
022 * @author Joern Huxhorn
023 * @author Ceki Gulcu
024 */
025public class DateFormattingThreadedThroughputCalculator {
026
027    static int THREAD_COUNT = 16;
028    static long OVERALL_DURATION_IN_MILLIS = 3000;
029
030    public static void main(String args[]) throws InterruptedException {
031
032        ThreadedThroughputCalculator tp = new ThreadedThroughputCalculator(OVERALL_DURATION_IN_MILLIS);
033        tp.printEnvironmentInfo("DateFormatting");
034
035        for (int i = 0; i < 2; i++) {
036            tp.execute(buildArray(FormattingModel.SDF));
037            tp.execute(buildArray(FormattingModel.JODA));
038        }
039
040        tp.execute(buildArray(FormattingModel.JODA));
041        tp.printThroughput("JODA: ");
042
043        tp.execute(buildArray(FormattingModel.SDF));
044        tp.printThroughput("SDF:  ");
045
046    }
047
048    static SelectiveDateFormattingRunnable[] buildArray(FormattingModel model) {
049        SelectiveDateFormattingRunnable[] array = new SelectiveDateFormattingRunnable[THREAD_COUNT];
050        for (int i = 0; i < THREAD_COUNT; i++) {
051            array[i] = new SelectiveDateFormattingRunnable(model);
052        }
053        return array;
054    }
055
056}