MOA 12.03
Real Time Analytics for Data Streams
MeasureStreamSpeed.java
Go to the documentation of this file.
00001 /*
00002  *    MeasureStreamSpeed.java
00003  *    Copyright (C) 2007 University of Waikato, Hamilton, New Zealand
00004  *    @author Richard Kirkby (rkirkby@cs.waikato.ac.nz)
00005  *
00006  *    This program is free software; you can redistribute it and/or modify
00007  *    it under the terms of the GNU General Public License as published by
00008  *    the Free Software Foundation; either version 3 of the License, or
00009  *    (at your option) any later version.
00010  *
00011  *    This program is distributed in the hope that it will be useful,
00012  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *    GNU General Public License for more details.
00015  *
00016  *    You should have received a copy of the GNU General Public License
00017  *    along with this program. If not, see <http://www.gnu.org/licenses/>.
00018  *    
00019  */
00020 package moa.tasks;
00021 
00022 import moa.core.Measurement;
00023 import moa.core.ObjectRepository;
00024 import moa.core.TimingUtils;
00025 import moa.evaluation.LearningEvaluation;
00026 import moa.options.ClassOption;
00027 import moa.options.IntOption;
00028 import moa.streams.InstanceStream;
00029 
00036 public class MeasureStreamSpeed extends MainTask {
00037 
00038     @Override
00039     public String getPurposeString() {
00040         return "Measures the speed of a stream.";
00041     }
00042 
00043     private static final long serialVersionUID = 1L;
00044 
00045     public ClassOption streamOption = new ClassOption("stream", 's',
00046             "Stream to measure.", InstanceStream.class,
00047             "generators.RandomTreeGenerator");
00048 
00049     public IntOption generateSizeOption = new IntOption("generateSize", 'g',
00050             "Number of examples.", 10000000, 0, Integer.MAX_VALUE);
00051 
00052     @Override
00053     protected Object doMainTask(TaskMonitor monitor, ObjectRepository repository) {
00054         TimingUtils.enablePreciseTiming();
00055         int numInstances = 0;
00056         InstanceStream stream = (InstanceStream) getPreparedClassOption(this.streamOption);
00057         long genStartTime = TimingUtils.getNanoCPUTimeOfCurrentThread();
00058         while (numInstances < this.generateSizeOption.getValue()) {
00059             stream.nextInstance();
00060             numInstances++;
00061         }
00062         double genTime = TimingUtils.nanoTimeToSeconds(TimingUtils.getNanoCPUTimeOfCurrentThread()
00063                 - genStartTime);
00064         return new LearningEvaluation(
00065                 new Measurement[]{
00066                     new Measurement("Number of instances generated",
00067                     numInstances),
00068                     new Measurement("Time elapsed", genTime),
00069                     new Measurement("Instances per second", numInstances
00070                     / genTime)});
00071     }
00072 
00073     @Override
00074     public Class<?> getTaskResultType() {
00075         return LearningEvaluation.class;
00076     }
00077 }
 All Classes Namespaces Files Functions Variables Enumerations