Пример #1
0
MojErr MojDbPerfCreateTest::batchPutLargeArrayObj(MojDb& db, const MojChar* kindId, MojUInt64& lgArrayObjTime)
{
	timespec startTime;
	startTime.tv_nsec = 0;
	startTime.tv_sec = 0;
	timespec endTime;
	endTime.tv_nsec = 0;
	endTime.tv_sec = 0;

	MojObject objArray;

	for (MojUInt64 i = 0; i < numInsert; i++) {
		MojObject obj;
		MojErr err = obj.putString(MojDb::KindKey, kindId);
		MojTestErrCheck(err);
		err = createLargeArrayObj(obj, i);
		MojTestErrCheck(err);
		err = objArray.push(obj);
		MojTestErrCheck(err);
	}

	MojObject::ArrayIterator begin;
	MojErr err = objArray.arrayBegin(begin);
	MojTestErrCheck(err);
	MojObject::ConstArrayIterator end = objArray.arrayEnd();
	clock_gettime(CLOCK_REALTIME, &startTime);
	err = db.put(begin, end);
	MojTestErrCheck(err);
	clock_gettime(CLOCK_REALTIME, &endTime);
	lgArrayObjTime += timeDiff(startTime, endTime);
	totalTestTime += timeDiff(startTime, endTime);

	return MojErrNone;
}
Пример #2
0
double MeasTrend::trend() {
  if (timeDiff() > 0) {
    return (double) valueDiff() / (double) timeDiff();
  } else {
    return 0.0;
  }
}
Пример #3
0
MojErr MojDbPerfCreateTest::putLargeArrayObj(MojDb& db, const MojChar* kindId, MojUInt64& lgArrayObjTime)
{
	timespec startTime;
	startTime.tv_nsec = 0;
	startTime.tv_sec = 0;
	timespec endTime;
	endTime.tv_nsec = 0;
	endTime.tv_sec = 0;

	for (MojUInt64 i = 0; i < numInsert; i++) {
		MojObject obj;
		MojErr err = obj.putString(MojDb::KindKey, kindId);
		MojTestErrCheck(err);
		err = createLargeArrayObj(obj, i);
		MojTestErrCheck(err);

		clock_gettime(CLOCK_REALTIME, &startTime);
		err = db.put(obj);
		MojTestErrCheck(err);
		clock_gettime(CLOCK_REALTIME, &endTime);
		lgArrayObjTime += timeDiff(startTime, endTime);
		totalTestTime += timeDiff(startTime, endTime);
	}

	return MojErrNone;
}
Пример #4
0
/*
 * Destroy modules in a sync chain
 *
 * Args:
 *   traceSetContext: traceset
 */
void teardownSyncChain(LttvTracesetContext* const traceSetContext)
{
	struct TracesetChainState* tracesetChainState;
	SyncState* syncState;
	struct timeval endTime;
	struct rusage endUsage;

	tracesetChainState= g_hash_table_lookup(tracesetChainStates, traceSetContext);
	syncState= tracesetChainState->syncState;

	freeAllFactors(syncState->processingModule->finalizeProcessing(syncState),
		syncState->traceNb);

	// Write graphs file
	if (optionEvalGraphs)
	{
		writeGraphsScript(syncState);

		if (fclose(syncState->graphsStream) != 0)
		{
			g_error("%s", strerror(errno));
		}
	}

	printStats(syncState);

	syncState->processingModule->destroyProcessing(syncState);
	if (syncState->matchingModule != NULL)
	{
		syncState->matchingModule->destroyMatching(syncState);
	}
	if (syncState->analysisModule != NULL)
	{
		syncState->analysisModule->destroyAnalysis(syncState);
	}
	if (syncState->reductionModule != NULL)
	{
		syncState->reductionModule->destroyReduction(syncState);
	}

	free(syncState);

	gettimeofday(&endTime, 0);
	getrusage(RUSAGE_SELF, &endUsage);

	timeDiff(&endTime, &tracesetChainState->startTime);
	timeDiff(&endUsage.ru_utime, &tracesetChainState->startUsage.ru_utime);
	timeDiff(&endUsage.ru_stime, &tracesetChainState->startUsage.ru_stime);

	printf("Evaluation time:\n");
	printf("\treal time: %ld.%06ld\n", endTime.tv_sec, endTime.tv_usec);
	printf("\tuser time: %ld.%06ld\n", endUsage.ru_utime.tv_sec,
		endUsage.ru_utime.tv_usec);
	printf("\tsystem time: %ld.%06ld\n", endUsage.ru_stime.tv_sec,
		endUsage.ru_stime.tv_usec);

	g_hash_table_remove(tracesetChainStates, traceSetContext);
	free(tracesetChainState);
}
Пример #5
0
static boolean getOurAck(struct rudp *ru, struct timeval *startTv, struct sockaddr_in *sai)
/* Wait for acknowledgement to the message we just sent.
 * The set should be zeroed out. Only wait for up to
 * ru->timeOut microseconds.   Prints a message and returns FALSE
 * if there's a problem.   */
{
struct rudpHeader head;
int readSize;
int timeOut = ru->timeOut;
struct sockaddr_in retFrom;
unsigned int retFromSize = sizeof(retFrom);

for (;;)
    {
    /* Set up select with our time out. */
    int dt;
    struct timeval tv;

    if (readReadyWait(ru->socket, timeOut))
	{
	/* Read message and if it's our ack return true.   */
	readSize = recvfrom(ru->socket, &head, sizeof(head), 0, 
		    (struct sockaddr*)&retFrom, &retFromSize);
	if (readSize >= sizeof(head) && head.type == rudpAck && head.id == ru->lastId)
	    {
	    if ((sai->sin_addr.s_addr==retFrom.sin_addr.s_addr) &&
		(sai->sin_port==retFrom.sin_port))
		{
		gettimeofday(&tv, NULL);
		dt = timeDiff(startTv, &tv);
		rudpAddRoundTripTime(ru, dt);
		return TRUE;
		}
	    else
		{
		char retFromDottedQuad[17];
		char saiDottedQuad[17];
		internetIpToDottedQuad(ntohl(retFrom.sin_addr.s_addr), retFromDottedQuad);
		internetIpToDottedQuad(ntohl(sai->sin_addr.s_addr), saiDottedQuad);
		warn("rudp: discarding mistaken ack from %s:%d by confirming recipient ip:port %s:%d"
		    , retFromDottedQuad, retFrom.sin_port
		    , saiDottedQuad, sai->sin_port
		    );
		}
	    }
	}

    /* If we got to here then we did get a message, but it's not our
     * ack.  We ignore the message and loop around again,  but update
     * our timeout so that we won't keep getting other people's messages
     * forever. */
    gettimeofday(&tv, NULL);
    timeOut = ru->timeOut - timeDiff(startTv, &tv);
    if (timeOut <= 0)
	return FALSE;
    }
}
Пример #6
0
double Timer::getTime() {
  if (isRunning()) {
    timeval temp;
    gettimeofday(&temp, NULL);
    double dusec = timeDiff(mBegin, temp);
    return dusec / TIME_SCALE;
  } else {
    double dusec = timeDiff(mBegin, mEnd);
    return dusec / TIME_SCALE;
  }
}
Пример #7
0
// put out flagged header entries: event ID, timestamps, comment prefix ...
int AMAcqScanOutput::startRecord( acqKey_t key, int eventno)
{
	AMAcqScanOutput *to = (AMAcqScanOutput *)key;
	acqOutputEvent_t *event;
	struct timeval curTime;

	const char *prefix = "";


	to->dataDelayList_.clear();
	to->dataDelay_ = true;

	// flag that some output is occuring
	to->outputState = TOH_HAS_CONTENT;
	event = to->find_event_number(eventno);
	if( event == NULL || ! to->isReady() )
		return -1;
	eventPrivate *evpr;
	evpr = (eventPrivate *)event->private_data;
	if( evpr == NULL)
		return 0;

	gettimeofday( &curTime, 0);

	if( evpr->commentPrefix)
	{
		to->sendOutputLine( "# ");
	}
	if( evpr->putEventID)
	{
		to->sendOutputLine( "%s%d", prefix, eventno);
		prefix = to->delimiter.c_str();
	}
	if( evpr->timeStamp)
	{
		to->sendOutputLine( "%s%.6f", prefix, doubleTime(curTime));
		prefix = to->delimiter.c_str();
	}
	if( evpr->rel0TimeStamp)
	{
		to->sendOutputLine( "%s%.6f", prefix, timeDiff(curTime, evpr->startTime) );
		prefix = to->delimiter.c_str();
	}
	if( evpr->relTimeStamp)
	{
		to->sendOutputLine( "%s%.6f", prefix, timeDiff(curTime, evpr->prevTime) );
		prefix = to->delimiter.c_str();
	}
	evpr->prevTime = curTime;
	if( *prefix)
		to->needDelimiter = TRUE;
	return 1;
}
Пример #8
0
void timePause(int b)
{
  if(b)
  {
    tPause = timeGetRelative();
    pause = 1;
  }
  else
  {
    pause = 0;
    begin = timeDiff(begin, timeDiff(tPause, timeGetRelative()));
  }
}
Пример #9
0
void tcpCountServer(char *portName)
/* tcpCountServer - A server that just returns a steadily increasing stream of numbers. 
 * This one is based on tcp */
{
int port = atoi(portName);
int ear, socket, size;
char buf[1024];
int count = 0;
struct timeval startTime, tv;
struct countMessage sendMessage, receiveMessage;

ear = netAcceptingSocket(port, 100);
gettimeofday(&startTime, NULL);
for (;;)
    {
    socket = netAccept(ear);
    if (socket < 0)
	errnoAbort("Couldn't accept first");
    size = netReadAll(socket, &receiveMessage, sizeof(receiveMessage));
    if (size < sizeof(receiveMessage))
        continue;
    gettimeofday(&tv, NULL);
    sendMessage.time = timeDiff(&startTime, &tv);
    sendMessage.echoTime = receiveMessage.time;
    sendMessage.count = ++count;
    sendMessage.message = receiveMessage.message + 256;
    write(socket, &sendMessage, sizeof(sendMessage));
    close(socket);
    if (size < 0)
	errnoAbort("Couldn't read first");
    if (!receiveMessage.message)
         break;
    }
printf("All done after %d\n", count);
}
Пример #10
0
double evalApproxK(matrix q, matrix x, unint **NNs, unint K){
  unint i,j,k;
  struct timeval tvB, tvE;
  unint **nnCorrect = (unint**)calloc(q.pr, sizeof(*nnCorrect));
  real **dT = (real**)calloc(q.pr, sizeof(*dT));
  for(i=0; i<q.pr; i++){
    nnCorrect[i] = (unint*)calloc(K, sizeof(**nnCorrect));
    dT[i] = (real*)calloc(K, sizeof(**dT));
  }

  gettimeofday(&tvB,NULL); 
  bruteK(x, q, nnCorrect, dT, K);
  gettimeofday(&tvE,NULL); 
  
  unsigned long ol = 0;
  for(i=0; i<q.r; i++){
    for(j=0; j<K; j++){
      for(k=0; k<K; k++){
	ol += (NNs[i][j] == nnCorrect[i][k]);
      }
    }
  }
  printf("avg overlap = %6.4f / %d\n", ((double)ol)/((double)q.r), K);
  printf("(bruteK took %6.4f seconds) \n",timeDiff(tvB,tvE));
  
  for(i=0; i<q.pr; i++){
    free(nnCorrect[i]);
    free(dT[i]);
  }
  free(nnCorrect);
  free(dT);
  
  return ((double)ol)/((double)q.r);
}
Пример #11
0
static void 
viaDMAWaitTimeStamp(XvMCLowLevel *xl, CARD32 timeStamp, int doSleep) 
{
    struct timeval now, then;
    struct timezone here;
    struct timespec sleep, rem;

    if (xl->use_agp && (xl->lastReadTimeStamp - timeStamp > (1 << 23))) {
	sleep.tv_nsec = 1;
	sleep.tv_sec = 0;
	here.tz_minuteswest = 0;
	here.tz_dsttime = 0;
	gettimeofday(&then,&here);
 
	while(((xl->lastReadTimeStamp = *xl->tsP) - timeStamp) > (1 << 23)) {
	    gettimeofday(&now,&here); 
	    if (timeDiff(&now,&then) > VIA_DMAWAITTIMEOUT) {
		if(((xl->lastReadTimeStamp = *xl->tsP) - timeStamp) > (1 << 23)) {
		    xl->errors |= LL_DMA_TIMEDOUT;
		    break;
		}
	    }
	    if (doSleep) nanosleep(&sleep, &rem);
	}
    }
}
Пример #12
0
int main(void)
{
	logOpen();
	initXWindows();
	init_opengl();
	Game game;
	init(&game);
	srand(time(NULL));
	clock_gettime(CLOCK_REALTIME, &timePause);
	clock_gettime(CLOCK_REALTIME, &timeStart);
	int done=0;
	while (!done) {
		while (XPending(dpy)) {
			XEvent e;
			XNextEvent(dpy, &e);
			check_resize(&e);
			check_mouse(&e);
			done = check_keys(&e);
		}
		clock_gettime(CLOCK_REALTIME, &timeCurrent);
		timeSpan = timeDiff(&timeStart, &timeCurrent);
		timeCopy(&timeStart, &timeCurrent);
		physicsCountdown += timeSpan;
		while (physicsCountdown >= physicsRate) {
			physics(&game);
			physicsCountdown -= physicsRate;
		}
		render(&game);
		glXSwapBuffers(dpy, win);
	}
	cleanupXWindows();
	cleanup_fonts();
	logClose();
	return 0;
}
Пример #13
0
Файл: func.c Проект: wareya/gzrt
double timeSinceStart ( void )
{
    struct timeval tmp;
    
    gettimeofday( &tmp, NULL );
    
    return timeDiff( &tmp, &conf.gzrt_start );
}
Пример #14
0
void Timer::stop(void){
  // For better accuracy, take Time first ...
  clock_gettime(CLOCK_REALTIME, &stop_s);

  if(!isLaunched)
    throw Exception("Trying to Stop Timer without Starting it");

  elapsedTime   = timeDiff();
  hasBeenStoped = true;
}
Пример #15
0
void adcReadRun(void)
{
  uint8_t low, high;
  static uint32_t oldTime;

  switch (a2dState)
  {
    case a2d_idle:
      if (itIsTimeToStartScanning())
      {
        a2dPin = 0;
        a2dState = a2d_SetMux;
      }
      break;

    case a2d_SetMux:
      if (pinToRead[a2dPin])
      {
        ADMUX = (DEFAULT << 6) | (a2dPin & 0x07);
        oldTime = micros();
        a2dState = a2d_InputSettleWait;
      }
      else
      {
        a2dPin++;
      }
      break;

    case a2d_InputSettleWait:
      if (timeDiff(micros(), oldTime) >= 500)
      {
        // start the conversion
        sbi(ADCSRA, ADSC);
        a2dState = a2d_AwaitConversionComplete;
      }
      break;

    case a2d_AwaitConversionComplete:
      if (bit_is_clear(ADCSRA, ADSC))
      {
        low  = ADCL;
        high = ADCH;
        adcValue[a2dPin] = (high << 8) | low;
        a2dPin++;
        a2dState = a2d_SetMux;
      }
      break;
  }

  if (a2dPin >= MAX_CHANNELS)
  {
    a2dState = a2d_idle;
  }

}
Пример #16
0
void searchExact2(matrix q, matrix x, matrix r, rep *ri, unint *NNs){
  unint i, j;
  unint *repID = (unint*)calloc(q.pr, sizeof(*repID));
  real *dToReps = (real*)calloc(q.pr, sizeof(*dToReps));
  intList *toSearch = (intList*)calloc(r.pr, sizeof(*toSearch));
  for(i=0;i<r.pr;i++)
    createList(&toSearch[i]);
  
  struct timeval tvB,tvE;

  gettimeofday(&tvB,NULL);
  brutePar2(r,q,repID,dToReps);
  gettimeofday(&tvE,NULL);
  printf("[SE]brutePar2 time elapsed = %6.4f \n", timeDiff(tvB,tvE) );

  gettimeofday(&tvB,NULL);
#pragma omp parallel for private(j)
  for(i=0; i<r.r; i++){
    for(j=0; j<q.r; j++ ){
      real temp = distVec( q, r, j, i );
      //dToRep[j] is current UB on dist to j's NN
      //temp - ri[i].radius is LB to dist belonging to rep i
      if( dToReps[j] >= temp - ri[i].radius)
	addToList(&toSearch[i], j); //need to search rep i
    }
    while(toSearch[i].len % CL != 0)
      addToList(&toSearch[i],DUMMY_IDX);
  }
  gettimeofday(&tvE,NULL);
  printf("[SE]loop time elapsed = %6.4f \n", timeDiff(tvB,tvE) );

  gettimeofday(&tvB,NULL);
  bruteListRev(x,q,ri,toSearch,r.r,NNs,dToReps);
  gettimeofday(&tvE,NULL);
  printf("[SE]bruteListRev time elapsed = %6.4f \n", timeDiff(tvB,tvE) );

  for(i=0;i<r.pr;i++)
    destroyList(&toSearch[i]);
  free(toSearch);
  free(repID);
  free(dToReps);
}
Пример #17
0
void cdDetectClap(
	const unsigned char* const bytes, 
	const size_t length,  
	void (*Callback)(double energy, int64_t elapsedSinceLastClap)
)
{
	int i;
	double instantEnergy = 0.0;
	double averageEnergy = 0.0;
	double sum = 0.0;

	//Calculate instant energy of sample buffer
	//ONLY handles mono audio 16bit little endian format!
	for (i = 1; i < length; i += 2)
	{
		short sample_s = ((bytes[i] & 0xFF) << 8) | (bytes[i - 1] & 0xFF);
		sample_s *= SCALE_FACTOR;
		instantEnergy += ((double)sample_s * (double)sample_s);
	}

	//compute average local energy
	for (i = 0; i < ENERGY_BUFFER_SIZE; i++) {
		sum += energyBuffer[i];
	}
	averageEnergy = sum / (double)ENERGY_BUFFER_SIZE;

	//Update energy buffer
	energyBuffer[currentPos] = instantEnergy;

	//if history buffer full, shift the array 1 slot down
	if (shift) {
		//Remove the oldest energy to make room for new energy on top
		for (i = ENERGY_BUFFER_SIZE - 1; i > 0; i--) {
			energyBuffer[i] = energyBuffer[i - 1];
		}
		currentPos = 0;
	} else {
		currentPos--;
	}
	if (currentPos < 0) {
		currentPos = 0;
		shift = TRUE;
	}

	//determine clap
	if(instantEnergy > (sensitivity * averageEnergy)) 
	{
		struct timeval tCurr;
	 	gettimeofday(&tCurr, 0);
		int64_t elapsedMs = timeDiff(&tCurr, &tPrev);
		if(elapsedMs >= minGapMs && Callback) Callback(instantEnergy, elapsedMs);
		memcpy(&tPrev, &tCurr, sizeof(struct timeval));
	}
}
Пример #18
0
int main(void)
{
	logOpen();
	initXWindows();
	init_opengl();
	init();
	init_sounds();
	clock_gettime(CLOCK_REALTIME, &timePause);
	clock_gettime(CLOCK_REALTIME, &timeStart);
	while(!done) {
		while(XPending(dpy)) {
			XEvent e;
			XNextEvent(dpy, &e);
			check_resize(&e);
			check_mouse(&e);
			check_keys(&e);
		}
		//
		//Below is a process to apply physics at a consistent rate.
		//1. Get the time right now.
		clock_gettime(CLOCK_REALTIME, &timeCurrent);
		//2. How long since we were here last?
		timeSpan = timeDiff(&timeStart, &timeCurrent);
		//3. Save the current time as our new starting time.
		timeCopy(&timeStart, &timeCurrent);
		//4. Add time-span to our countdown amount.
		physicsCountdown += timeSpan;
		//5. Has countdown gone beyond our physics rate? 
		//       if yes,
		//           In a loop...
		//              Apply physics
		//              Reducing countdown by physics-rate.
		//              Break when countdown < physics-rate.
		//       if no,
		//           Apply no physics this frame.
		while(physicsCountdown >= physicsRate) {
			//6. Apply physics
			physics();
			//7. Reduce the countdown by our physics-rate
			physicsCountdown -= physicsRate;
		}
		//Always render every frame.
		render();
		glXSwapBuffers(dpy, win);
	}
	cleanupXWindows();
	cleanup_fonts();
	#ifdef USE_SOUND
	fmod_cleanup();
	#endif //USE_SOUND
	logClose();
	return 0;
}
Пример #19
0
static void * runWorker(void *arg) {
	int i;
	struct timeval tv1, tv2;
	gettimeofday(&tv1, NULL);
	gettimeofday(&tv2, NULL);
	while (duration > timeDiff(&tv1, &tv2)) {
		i = worker();
		usleep(sleeptime);
		gettimeofday(&tv2, NULL);
	}
	return NULL;
}
Пример #20
0
int main(void)
{
        int done=0;
        srand(time(NULL));
        initXWindows();
        init_opengl();
        //declare game object
        Game game;
        game.n=0;
	
	clock_gettime(CLOCK_REALTIME, &timePause);
	clock_gettime(CLOCK_REALTIME, &timeStart);

        //declare a box shape
	for(int i = 0; i<5; i++)
	{
        	game.box[i].width = 100;
        	game.box[i].height = 15;
       		
		game.box[i].center.x = 120 + (60*i);
       		game.box[i].center.y = 500 - (100*i);
	}

	game.circle.radius = .5;
        game.circle.center.x = 60 + 9*65;
        game.circle.center.y = 450- 8*60;


        //start animation
        while(!done) {
                while(XPending(dpy)) {
                        XEvent e;
                        XNextEvent(dpy, &e);
                        check_mouse(&e, &game);
                        done = check_keys(&e, &game);
		}

		clock_gettime(CLOCK_REALTIME, &timeCurrent);
		timeSpan = timeDiff(&timeStart, &timeCurrent);
		timeCopy(&timeStart, &timeCurrent);
		physicsCountdown += timeSpan;
		
		while(physicsCountdown >= physicsRate) {
			physics(&game);
			physicsCountdown -= physicsRate;
		}
                movement(&game);
                render(&game);
                glXSwapBuffers(dpy, win);
        }
        cleanupXWindows();
        return 0;
}
Пример #21
0
struct timespec timeGetRelative()
{
  if(pause)
    return tPause;

  struct timespec r;
  if(clock_gettime(CLOCK_REALTIME, &r) < 0)
  {
    perror("clock_gettime()");
    exit(1);
  }
  return timeDiff(r, begin);
}
Пример #22
0
void udpCountServer(char *portName)
/* countServer - A server that just returns a steadily increasing stream of numbers. */
{
int port = atoi(portName);
int ear, size;
char buf[1024];
int count = 0;
struct timeval startTime, tv;
struct countMessage sendMessage, receiveMessage;
struct sockaddr_in sai;


ZeroVar(&sai);
sai.sin_family = AF_INET;
sai.sin_port = htons(port);
sai.sin_addr.s_addr = INADDR_ANY;
ear = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
if (bind(ear, (struct sockaddr *)&sai, sizeof(sai)) < 0)
    errAbort("Couldn't bind ear");
gettimeofday(&startTime, NULL);
for (;;)
    {
    int err;
    int saiSize = sizeof(sai);
    ZeroVar(&sai);
    sai.sin_family = AF_INET;
    err = recvfrom(ear, &receiveMessage, sizeof(receiveMessage), 
    	0, (struct sockaddr *)&sai, &saiSize);
    if (err < 0)
	{
        warn("couldn't receive %s", strerror(errno));
	continue;
	}
    if (err != sizeof(receiveMessage))
        {
	warn("Message truncated");
	continue;
	}
    gettimeofday(&tv, NULL);
    sendMessage.time = timeDiff(&startTime, &tv);
    sendMessage.echoTime = receiveMessage.time;
    sendMessage.count = ++count;
    sendMessage.message = receiveMessage.message + 256;
    sendto(ear, &sendMessage, sizeof(sendMessage), 0, &sai, sizeof(sai));
    if (!receiveMessage.message)
         break;
    }
close(ear);
printf("All done after %d\n", count);
}
Пример #23
0
int getWorkerTime() {
	int cnt, i;
	struct timeval tv1, tv2;
	cnt = 0;
	gettimeofday(&tv1, NULL);
	gettimeofday(&tv2, NULL);
	// Warmup of 1 sec
	while (1000000 > timeDiff(&tv1, &tv2)) {
		i = worker();
		usleep(1);
		gettimeofday(&tv2, NULL);
	}
	gettimeofday(&tv1, NULL);
	gettimeofday(&tv2, NULL);
	// Meassure for 4 sec
	while (4*1000000 > timeDiff(&tv1, &tv2)) {
		i = worker();
		usleep(0);
		gettimeofday(&tv2, NULL);
		cnt++;
	}
	return timeDiff(&tv1, &tv2)/cnt;
}
Пример #24
0
Файл: pa06.c Проект: kuos/ECE264
/**
 * Program entry point
 */
int main(int argc, char * * argv)
{
    if(argc != 3) {
    	printUsage();
    	return 0;
    }

    // What was the input number?
    uint128 n = alphaTou128(argv[1]);
    char * n_str = u128ToString(n); 

    // How many concurrent threads?
    errno = 0; // so we know if strtol fails
    int n_threads = strtol(argv[2], NULL, 10);

    // Was there an error in the input arguments?
        int error = FALSE;
    if(errno != 0 || n_threads <= 0) {
	fprintf(stderr, "2nd argument must be a valid integer >= 1, aborting.\n");
	error = TRUE;
    }
    if(n_str && strcmp(n_str, argv[1]) != 0) {
	fprintf(stderr, "1st argument must be a valid 128-bit integer: '%s' != '%s', aborting.\n", n_str, argv[1]);
	error = TRUE;
    }

    if(error) {
	free(n_str);
	exit(1);
    }
    free(n_str);
   
  
    struct timeval time1;
    struct timeval time2;
    gettimeofday(&time1, NULL);
    printf("Testing if '%s' is prime with %d threads: ", argv[1], n_threads);
    fflush(stdout);
    int is_prime = primalityTestParallel(n, n_threads);
    gettimeofday(&time2, NULL);
    if(is_prime) {
	printf("TRUE");
    } else {
	printf("FALSE");
    }
    printf(", %8.4fs\n", timeDiff(time1, time2));

    return EXIT_SUCCESS;
}
Пример #25
0
void BasicGLPane::updateSim(wxTimerEvent & event) {

    dmTimespec tv_now;
    dmGetSysTime(&tv_now);

    real_time_ratio = (simThread->sim_time-last_render_time)/timeDiff(last_draw_tv, tv_now);
    last_render_time = simThread->sim_time;

    dmGetSysTime(&last_draw_tv);

    camera->setPerspective(45.0, (GLfloat)getWidth()/(GLfloat)getHeight(), 1.0, 200.0);
    camera->update(mouse);
    camera->applyView();
    Refresh(); // ask for repaint

    // if you want the GL light to move with the camera, comment the following two lines - yiping
    GLfloat light_position0[] = { 1.0, 1.0, 1.0, 0.0 };
    glLightfv (GL_LIGHT0, GL_POSITION, light_position0);

    GLfloat light_position1[] = { -1.0, -1.0, 1.0, 0.0 };
    glLightfv (GL_LIGHT1, GL_POSITION, light_position1);


    timer_count++;

    double rtime = timeDiff(first_tv, tv_now);
    double update_time = timeDiff(update_tv, tv_now);

    if (update_time > 2.5)
    {
        timer_count ++;
        cerr << "time/real_time: " << simThread->sim_time << '/' << rtime
             << "  frame_rate: " << (double) timer_count/rtime << endl;
        dmGetSysTime(&update_tv);
    }
}
Пример #26
0
int main(int argc, char **argv){

  if(argc < 2){
    printf("Użycie: ./seqmain #size\n");
    return -1;
  }

  struct timespec start, end;

  int size = atoi( argv[1] );
  int i;
  int count = 0;

  double *x = (double*) malloc( size * sizeof(double) );
  double *y = (double*) malloc( size * sizeof(double) );

  srand( 161015 );

  for(i=0; i < size; i++){
    x[i] = (double) rand() / (double) RAND_MAX;
    y[i] = (double) rand() / (double) RAND_MAX;
  }

  clock_gettime(CLOCK_MONOTONIC, &start);

  for(i = 0; i < size; i++){
    if( (x[i] * x[i]) + (y[i] * y[i]) <= 1){
      count = count + 1; 
    }
  }

  clock_gettime(CLOCK_MONOTONIC, &end);

  double pi_4 = ( (double) count ) / size;

  
  printf("\nsequence \t");
  printf(/*"size : */"%d\t", size);
  printf(/*"count: */"%d\t", count);
  printf(/*"PI   : */"%.8f\t", pi_4 * 4);
  printf(/*"time : */"%.16f\n", timeDiff(&end, &start));


  free(x);
  free(y);

  return 0;
}
Пример #27
0
Файл: msg.c Проект: wareya/gzrt
void gzrt_kappend ( char * mesg )
{
    static struct DebugMesg * last;
    struct DebugMesg * ptr = &dmesgbase;
    static volatile int lock;
    
    /* Locked? */
    while( lock );
    lock = 1;
    
    /* Last already set? */
    if( last )
        ptr = last;
    
    /* Find end of list */
    while( ptr->next )
        ptr = ptr->next;
    
    /* New node? */
    if( ptr->mesg )
    {
        /* Allocate memory */
        ptr->next = calloc( sizeof(struct DebugMesg), 1 );
        
        /* Walk */
        ptr = ptr->next;
    }
    
    /* Store latest */
    if( last != ptr )
        last = ptr;
    
    /* Store message */
    ptr->mesg = mesg;
    
    /* Store time */
    gettimeofday( &ptr->tv, NULL );
    
    /* Print */
    fprintf( stderr, 
      "[" ANSI_SET_FG_CYAN "%8.2f" ANSI_RESET_DEFAULT "] %s\n", 
      timeDiff( &ptr->tv, &conf.gzrt_start ),
      mesg );
    
    /* Unlock */
    lock = 0;
}
Пример #28
0
cpCommand cpRecogniseCommand(void)
{
	//Basic case: Nothing was captured
	if(buffer_empty()) return cpCmdUnknown;

	struct timeval tCurr;
	gettimeofday(&tCurr, 0);
	int64_t elapsedMs = timeDiff(&tCurr, &tStart);
	
	if(elapsedMs >= (COMMAND_BUFFER_SIZE * 200))
	{
		//Matched 'Last Command' (Single clap) pattern 
		if(!memcmp(buffer, repeatLastCmdPattern, COMMAND_BUFFER_SIZE) 
			&& lastCommand != cpCmdUnknown)
		{
			reset(); 
			return lastCommand;
		}

		int i, j;
		for(i = 0; i < ARRAY_SIZE(commands); i++)
		{
			for(j = 0; j < ARRAY_SIZE(commands[i].patterns); j++)
			{
				//We've found a match!
				if(!memcmp(buffer, commands[i].patterns[j], COMMAND_BUFFER_SIZE))
				{
					reset();
					
					//Remember last command (so that it can be repeated via a single clap)
					//Exclude cpCmdPower command from this rule
					if(commands[i].commandId == cpCmdPower) lastCommand = cpCmdUnknown;
					else lastCommand = commands[i].commandId;					
	
					return commands[i].commandId;
				}
			}
		}

		lastCommand = cpCmdUnknown;
	}
	
	return cpCmdUnknown;
}
Пример #29
0
int main(void)
{
    int done=0;
    srand(time(NULL));
    initXWindows();
    init_opengl();
    init_sounds();

    clock_gettime(CLOCK_REALTIME, &timePause);
    clock_gettime(CLOCK_REALTIME, &timeStart);
    //declare game object
    Game game;

    fmod_playsound(1);
    //start animation
    while(!done) {
	while(XPending(dpy)) {
	    XEvent e;
	    XNextEvent(dpy, &e);
	    check_resize(&e);
	    check_mouse(&e, &game);
	    done = check_keys(&e, &game);
	}
	clock_gettime(CLOCK_REALTIME, &timeCurrent);
	timeSpan = timeDiff(&timeStart, &timeCurrent);
	timeCopy(&timeStart, &timeCurrent);
	movementCountdown += timeSpan;
	while(movementCountdown >= movementRate)
	{
	    movement(&game);
	    movementCountdown -= movementRate;
	}
	render(&game);
	glXSwapBuffers(dpy, win);
    }
    cleanupXWindows();
    cleanup_fonts();
#ifdef USE_SOUND
    fmod_cleanup();
#endif //USE_SOUND
    return 0;
}
Пример #30
0
int main(void)
{
    logOpen();
    initXWindows();
    init_opengl();
    init();
    //buttonsInit();------------------------------------------------------------------
    init_sounds();
    clock_gettime(CLOCK_REALTIME, &timePause);
    clock_gettime(CLOCK_REALTIME, &timeStart);
    while(!done) {
        while(XPending(dpy)) {
            XEvent e;
            XNextEvent(dpy, &e);
            check_resize(&e);
            check_mouse(&e);
            GOcheck_mouse(&e);
            check_keys(&e);

        }
        clock_gettime(CLOCK_REALTIME, &timeCurrent);
        timeSpan = timeDiff(&timeStart, &timeCurrent);
        timeCopy(&timeStart, &timeCurrent);
        physicsCountdown += timeSpan;
        while(physicsCountdown >= physicsRate) {
            physics();
            physicsCountdown -= physicsRate;
        }
        render();
        glXSwapBuffers(dpy, win);
    }
    cleanupXWindows();
    cleanup_fonts();
#ifdef USE_SOUND
    fmod_cleanup();
#endif //USE_SOUND
    logClose();
    return 0;
}