001/*
002Below is the copyright agreement for the Ptolemy II system.
003
004Copyright (c) 2006-2015 The Regents of the University of California.
005All rights reserved.
006
007Permission is hereby granted, without written agreement and without
008license or royalty fees, to use, copy, modify, and distribute this
009software and its documentation for any purpose, provided that the above
010copyright notice and the following two paragraphs appear in all copies
011of this software.
012
013IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY
014FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
015ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
016THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
017SUCH DAMAGE.
018
019THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
020INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
021MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
022PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
023CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
024ENHANCEMENTS, OR MODIFICATIONS.
025 */
026
027package ptolemy.kernel.test;
028
029import ptolemy.kernel.ComponentEntity;
030
031/**
032 Class that creates lots of ComponentEntities.
033 * @author Christopher Brooks
034 * @version $Id$
035 * @since Ptolemy II 6.0
036 * @Pt.ProposedRating Red (cxh)
037 * @Pt.AcceptedRating Red (cxh)
038 */
039public class ComponentEntityTimeTest {
040    public static void main(String args[]) {
041        // FindBugs: Useless object stored in variable entities.
042        // However, this is for time testing, so we should keep this.
043        ComponentEntity entities[] = new ComponentEntity[10000];
044        long startTime = System.currentTimeMillis();
045
046        for (int i = 0; i < 10000; i++) {
047            entities[i] = new ComponentEntity();
048        }
049        long stopTime = System.currentTimeMillis();
050        Runtime runtime = Runtime.getRuntime();
051        long totalMemory = runtime.totalMemory() / 1024;
052        long freeMemory = runtime.freeMemory() / 1024;
053        System.out.println(stopTime - startTime + " ms. Memory: " + totalMemory
054                + " K Free: " + freeMemory + " K ("
055                + Math.round((double) freeMemory / (double) totalMemory * 100.0)
056                + "%)");
057
058    }
059}