summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Turner <mattst88@gmail.com>2008-11-14 04:13:16 +0000
committerMatt Turner <mattst88@gmail.com>2008-11-14 04:13:16 +0000
commit1c42c325dafb487fa554dc8b93e05780bd47662c (patch)
treeae0e29cb4597d8f4b7f9470c0f0a8e7535c70a2e
parent70e35dac3ac20a4554bce8b30f236d220e22487e (diff)
-- Remove stop watch functions from neural.c and emfloat.c
git-svn-id: svn://mattst88.com/svn/cleanbench/trunk@27 0d43b9a7-5ab2-4d7b-af9d-f64450cef757
-rw-r--r--emfloat.c17
-rw-r--r--neural.c151
2 files changed, 69 insertions, 99 deletions
diff --git a/emfloat.c b/emfloat.c
index e9388c5..b1c822e 100644
--- a/emfloat.c
+++ b/emfloat.c
@@ -26,6 +26,7 @@
#include <stdio.h>
#include <string.h>
+#include <time.h>
#include "nmglobal.h"
#include "emfloat.h"
@@ -93,16 +94,11 @@ unsigned long DoEmFloatIteration(InternalFPF *abase,
InternalFPF *cbase,
unsigned long arraysize, unsigned long loops)
{
-unsigned long elapsed; /* For the stopwatch */
+ clock_t start, stop;
static unsigned char jtable[16] = {0,0,0,0,1,1,1,1,2,2,2,2,2,3,3,3};
unsigned long i;
-#ifdef DEBUG
-int number_of_loops;
-#endif
-/*
-** Begin timing
-*/
-elapsed=StartStopwatch();
+
+ start = clock();
/*
** Each pass through the array performs operations in
@@ -137,7 +133,10 @@ while(loops--)
break;
}
}
- return(StopStopwatch(elapsed));
+
+ stop = clock();
+
+ return stop - start;
}
/***********************
diff --git a/neural.c b/neural.c
index f7ac393..d8ae793 100644
--- a/neural.c
+++ b/neural.c
@@ -4,6 +4,7 @@
#include <string.h>
#include <math.h>
#include <limits.h>
+#include <time.h>
#include "nmglobal.h"
#include "nbench1.h"
@@ -86,7 +87,7 @@ int learned; /* flag--if TRUE, network has learned all patterns */
/*
** PROTOTYPES
*/
-static unsigned long DoNNetIteration(unsigned long nloops);
+static clock_t DoNNetIteration(unsigned long nloops);
static void do_mid_forward(int patt);
static void do_out_forward();
void display_output(int patt);
@@ -113,88 +114,58 @@ static int read_data_file();
** should be on the local directory (from which the
** benchmark program in launched).
*/
-void DoNNET(void)
-{
-NNetStruct *locnnetstruct; /* Local ptr to global data */
-char *errorcontext;
-unsigned long accumtime;
-double iterations;
-
-/*
-** Link to global data
-*/
-locnnetstruct=&global_nnetstruct;
-
-/*
-** Set error context
-*/
-errorcontext="CPU:NNET";
-
-/*
-** Init random number generator.
-** NOTE: It is important that the random number generator
-** be re-initialized for every pass through this test.
-** The NNET algorithm uses the random number generator
-** to initialize the net. Results are sensitive to
-** the initial neural net state.
-*/
-/* randnum(3L); */
-randnum((int32_t)3);
-
-/*
-** Read in the input and output patterns. We'll do this
-** only once here at the beginning. These values don't
-** change once loaded.
-*/
-if(read_data_file()!=0) {
- exit(1);
-}
-
-
-/*
-** See if we need to perform self adjustment loop.
-*/
-if(locnnetstruct->adjust==0)
-{
- /*
- ** Do self-adjustment. This involves initializing the
- ** # of loops and increasing the loop count until we
- ** get a number of loops that we can use.
- */
- for(locnnetstruct->loops=1L;
- locnnetstruct->loops<MAXNNETLOOPS;
- locnnetstruct->loops++)
- { /*randnum(3L); */
- randnum((int32_t)3);
- if(DoNNetIteration(locnnetstruct->loops)
- >global_min_ticks) break;
- }
-}
-
-/*
-** All's well if we get here. Do the test.
-*/
-accumtime=0L;
-iterations=(double)0.0;
-
-do {
- /* randnum(3L); */ /* Gotta do this for Neural Net */
- randnum((int32_t)3); /* Gotta do this for Neural Net */
- accumtime+=DoNNetIteration(locnnetstruct->loops);
- iterations+=(double)locnnetstruct->loops;
-} while(TicksToSecs(accumtime)<locnnetstruct->request_secs);
-
-/*
-** Clean up, calculate results, and go home. Be sure to
-** show that we don't have to rerun adjustment code.
-*/
-locnnetstruct->iterspersec=iterations / TicksToFracSecs(accumtime);
-
-if(locnnetstruct->adjust==0)
- locnnetstruct->adjust=1;
-
-
-return;
+void
+DoNNET(void)
+{
+ const char* context="CPU:NNET";
+ NNetStruct* locnnetstruct = &global_nnetstruct;
+ clock_t total_time = 0;
+ int iterations = 0;
+
+ /*
+ ** Init random number generator.
+ ** NOTE: It is important that the random number generator
+ ** be re-initialized for every pass through this test.
+ ** The NNET algorithm uses the random number generator
+ ** to initialize the net. Results are sensitive to
+ ** the initial neural net state.
+ */
+ randnum((int32_t)3);
+
+ /*
+ ** Read in the input and output patterns. We'll do this
+ ** only once here at the beginning. These values don't
+ ** change once loaded.
+ */
+ if(read_data_file()!=0) {
+ exit(1);
+ }
+
+ /*
+ ** See if we need to perform self adjustment loop.
+ */
+ if (locnnetstruct->adjust == FALSE) {
+ locnnetstruct->adjust = TRUE;
+ /*
+ ** Do self-adjustment. This involves initializing the
+ ** # of loops and increasing the loop count until we
+ ** get a number of loops that we can use.
+ */
+ for (locnnetstruct->loops = 1; locnnetstruct->loops < MAXNNETLOOPS; locnnetstruct->loops++) {
+ randnum((int32_t)3);
+ if(DoNNetIteration(locnnetstruct->loops) > global_min_ticks) {
+ break;
+ }
+ }
+ }
+
+ do {
+ randnum((int32_t)3); /* Gotta do this for Neural Net */
+ total_time += DoNNetIteration(locnnetstruct->loops);
+ iterations += locnnetstruct->loops;
+ } while (total_time < locnnetstruct->request_secs * CLOCKS_PER_SEC);
+
+ locnnetstruct->iterspersec = (double)(iterations * CLOCKS_PER_SEC) / total_time;
}
/********************
@@ -203,9 +174,10 @@ return;
** Do a single iteration of the neural net benchmark.
** By iteration, we mean a "learning" pass.
*/
-static unsigned long DoNNetIteration(unsigned long nloops)
+static clock_t
+DoNNetIteration(unsigned long nloops)
{
-unsigned long elapsed; /* Elapsed time */
+ clock_t start, stop;
int patt;
/*
@@ -215,7 +187,7 @@ int patt;
** since we don't have to stop and start the clock for
** each iteration.
*/
-elapsed=StartStopwatch();
+ start = clock();
while(nloops--)
{
randomize_wts();
@@ -236,11 +208,10 @@ while(nloops--)
numpasses ++;
learned = check_out_error();
}
-#ifdef DEBUG
-printf("Learned in %d passes\n",numpasses);
-#endif
}
-return(StopStopwatch(elapsed));
+ stop = clock();
+
+ return stop - start;
}
/*************************