/[svn]/linuxsampler/trunk/src/engines/gig/Profiler.cpp
ViewVC logotype

Contents of /linuxsampler/trunk/src/engines/gig/Profiler.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 326 - (show annotations) (download)
Tue Dec 21 04:59:11 2004 UTC (19 years, 4 months ago) by senkov
File size: 2727 byte(s)
Added profiler class

1 /***************************************************************************
2 * *
3 * LinuxSampler - modular, streaming capable sampler *
4 * *
5 * Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck *
6 * *
7 * This program is free software; you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation; either version 2 of the License, or *
10 * (at your option) any later version. *
11 * *
12 * This program is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU General Public License *
18 * along with this program; if not, write to the Free Software *
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
20 * MA 02111-1307 USA *
21 ***************************************************************************/
22
23 #include "Profiler.h"
24 #include <time.h>
25
26 namespace LinuxSampler { namespace gig {
27
28 unsigned long long Profiler::profilingSamples = 0;
29 unsigned long long Profiler::profilingTime = 0;
30 unsigned long long Profiler::ticksPerSecond = 0;
31
32 void Profiler::Calibrate( void )
33 {
34 clock_t start_time = clock();
35 unsigned long long start_clocks = Stamp();
36 volatile int a = 1;
37 volatile int b = 1;
38 for (volatile int i = 0; i < 100000000; i++)
39 {
40 a += b;
41 }
42 clock_t stop_time = clock();
43 unsigned long long stop_clocks = Stamp();
44 unsigned int diff_ticks = (unsigned int) (stop_clocks - start_clocks);
45 double diff_time = ((stop_time - start_time) / (double(CLOCKS_PER_SEC)));
46 ticksPerSecond = (unsigned long long)(double(diff_ticks) / diff_time);
47 }
48
49 unsigned int Profiler::GetBogoVoices(unsigned int SamplingFreq)
50 {
51 if (profilingSamples == 0) return 0;
52 unsigned int avgTicks = profilingTime / profilingSamples;
53 unsigned int samplesPerSecond = ticksPerSecond / avgTicks;
54 unsigned int bogoVoices = samplesPerSecond / SamplingFreq;
55 return bogoVoices;
56 }
57
58 }} // namespace LinuxSampler::gig

  ViewVC Help
Powered by ViewVC