KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jac > samples > photos > Bench


1 /*
2   Copyright (C) AOPSYS (http://www.aopsys.com)
3
4   This program is free software; you can redistribute it and/or modify
5   it under the terms of the GNU General Public License as published by
6   the Free Software Foundation; either version 2 of the License, or
7   (at your option) any later version.
8
9   This program is distributed in the hope that it will be useful,
10   but WITHOUT ANY WARRANTY; without even the implied warranty of
11   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12   GNU General Public License for more details.
13
14   You should have received a copy of the GNU General Public License
15   along with this program; if not, write to the Free Software
16   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */

17
18 package org.objectweb.jac.samples.photos;
19
20 import org.objectweb.jac.lib.Attachment;
21 import java.util.Iterator JavaDoc;
22
23 public class Bench {
24
25     /**
26      * A benchmark which creates lots of new photos and displays
27      * execution time used to do it. It then iterates on these photos
28      * and displays execution time.
29      */

30
31     public static void main(String JavaDoc[] args) throws Exception JavaDoc
32     {
33         //PhotoRepository rep = new PhotoRepository();
34

35         /*
36         System.out.println("Iterating on photos...");
37         Iterator i = rep.getPhotos().iterator();
38         while (i.hasNext()) {
39             System.out.print(".");
40             Photo p = (Photo)i.next();
41             p.getTitle();
42             p.getDate();
43             p.getRate();
44             p.getImage();
45             p.getAuthor().getFirstName();
46         }
47         System.out.println("benchmark runned in "+
48                            (System.currentTimeMillis()-_start_time)+"ms");
49         */

50     }
51
52     static public void createPhotos(int n) throws Throwable JavaDoc {
53         System.out.println("Creating photos "+n+"...");
54         /*
55         if (!ejp.tracer.TracerAPI.enableTracing()) {
56             throw ejp.tracer.TracerAPI.getInitializationError();
57         }
58         */

59         long _start_time = System.currentTimeMillis();
60         for (int i=0; i<n; i++) {
61             System.out.print(".");
62             Photo photo =
63                 new Photo("Test"+i,
64                           new Attachment("Hello".getBytes(),"text/plain","hello"));
65             //rep.addPhoto(photo);
66
photo.setAuthor(new Person());
67         }
68         System.out.println("object instanciations runned in "+
69                            (System.currentTimeMillis()-_start_time)+"ms");
70         /*
71         if (!ejp.tracer.TracerAPI.disableTracing()) {
72             throw ejp.tracer.TracerAPI.getInitializationError();
73         }
74         */

75         _start_time = System.currentTimeMillis();
76     }
77
78     static void printUsage() {
79         System.out.println("Usage: jac bench.jac <nbPhotos>");
80         System.out.println(" <nbPhotos>: number of photos to create");
81     }
82 }
83
84
Popular Tags