moved to: https://sites.google.com/site/cmzmasek/home/software/forester
[jalview.git] / forester / java / src / org / forester / development / Time.java
1 // $Id:
2 // FORESTER -- software libraries and applications
3 // for evolutionary biology research and applications.
4 //
5 // Copyright (C) 2008-2009 Christian M. Zmasek
6 // Copyright (C) 2008-2009 Burnham Institute for Medical Research
7 // All rights reserved
8 //
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU Lesser General Public
11 // License as published by the Free Software Foundation; either
12 // version 2.1 of the License, or (at your option) any later version.
13 //
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // Lesser General Public License for more details.
18 //
19 // You should have received a copy of the GNU Lesser General Public
20 // License along with this library; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 //
23 // Contact: phylosoft @ gmail . com
24 // WWW: https://sites.google.com/site/cmzmasek/home/software/forester
25
26 package org.forester.development;
27
28 import java.io.File;
29 import java.io.IOException;
30 import java.util.Date;
31
32 import org.forester.io.parsers.nhx.NHXParser;
33 import org.forester.phylogeny.Phylogeny;
34 import org.forester.phylogeny.PhylogenyNode;
35 import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory;
36 import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
37 import org.forester.util.BasicDescriptiveStatistics;
38 import org.forester.util.DescriptiveStatistics;
39
40 @SuppressWarnings( "unused")
41 public final class Time {
42
43     public static void main( final String[] args ) {
44         try {
45             final DescriptiveStatistics parse_stats = new BasicDescriptiveStatistics();
46             final DescriptiveStatistics post_stats = new BasicDescriptiveStatistics();
47             final DescriptiveStatistics pre_stats = new BasicDescriptiveStatistics();
48             final File f = new File( args[ 0 ] );
49             Phylogeny phy = null;
50             for( int i = 0; i < 10; i++ ) {
51                 final long start_time = new Date().getTime();
52                 phy = ParserBasedPhylogenyFactory.getInstance().create( f, new NHXParser() )[ 0 ];
53                 System.out.println( phy.getNumberOfExternalNodes() );
54                 parse_stats.addValue( new Date().getTime() - start_time );
55                 //
56                 PhylogenyNode n = null;
57                 final long start_time_post = new Date().getTime();
58                 final PhylogenyNodeIterator post = phy.iteratorPostorder();
59                 while ( post.hasNext() ) {
60                     n = post.next();
61                 }
62                 post_stats.addValue( new Date().getTime() - start_time_post );
63                 //
64                 final long start_time_pre = new Date().getTime();
65                 final PhylogenyNodeIterator pre = phy.iteratorPreorder();
66                 while ( pre.hasNext() ) {
67                     n = pre.next();
68                 }
69                 pre_stats.addValue( new Date().getTime() - start_time_pre );
70             }
71             System.out.println( "Parsing [ms]:" );
72             System.out.println( parse_stats.toString() );
73             System.out.println( "Post-order [ms]:" );
74             System.out.println( post_stats.toString() );
75             System.out.println( "Pre-order [ms]:" );
76             System.out.println( pre_stats.toString() );
77         }
78         catch ( final IOException e ) {
79             e.printStackTrace();
80         }
81     }
82 }