Пример #1
0
int main(int argc, const char * argv[]) {

    float Array[ARRAYSIZE] = {0};
    for (int i = 0; i<ARRAYSIZE; i++) {
        Array[i] = i;
    }
    double result ;
    
    gettimeofday(&start, NULL);
    result = GetStDev(Array, ARRAYSIZE);
    gettimeofday(&stop, NULL);
    result_time = timedifference_msec(stop, start);
    printf("C:STDEV RESULT : %f, code executed in %f microsecond \n", result,result_time);
    
    gettimeofday(&start, NULL);
    result = GetStDevIntrinsic(Array, ARRAYSIZE);
    gettimeofday(&stop, NULL);
    result_time = timedifference_msec(stop, start);
    printf("C_intric:STDEV RESULT : %f, code executed in %f microsecond \n", result,result_time);
    

    return 0;
}
Пример #2
0
void runHermesLite() {
	printf("runHermesLite \n");
	
	int count = 0;
	gettimeofday(&t10, 0);
	for (;;) {
		
		if (running) {
			sendPacket();
			count ++;
			if (count == 762) {
				//usleep(10 * 1000);
				count = 0;
				gettimeofday(&t11, 0);
				elapsed = timedifference_msec(t10, t11);

				//printf("Code packets executed in %f milliseconds.\n", elapsed);
				gettimeofday(&t10, 0);
			}
		}
	}
}
Пример #3
0
// main logging function
int logMesg( const char *fname, int lineno ,const char* group, int priority ,const char* str,...)
{
    logCheckAndInit();
    if ( priority < logMainInfo.logLevel ){
        return 0;
    }
    char buf[MAX_MESG_SIZE];
    int len_preamb = 0;
    int len_mesg;
    ssize_t len;
    va_list argptr;
    va_start(argptr, str);
    if ( logMainInfo.flags & LOG_PRINT_TIME ){
        struct timeval t1;
        float elapsed;
        gettimeofday(&t1, 0);
        elapsed = timedifference_msec( logMainInfo.startTime, t1);
        len_preamb+=snprintf( buf + len_preamb, MAX_MESG_SIZE-1-len_preamb, "[%0.3f]",  elapsed);
    }
    if ( logMainInfo.flags & LOG_PRINT_LEVEL_DESCRIPTION ){
        len_preamb+=snprintf( buf + len_preamb, MAX_MESG_SIZE-1-len_preamb,
                              "%s:", LOGLEVELS_DESCRIPTIONS[priority]);
    }
    if ( logMainInfo.flags & LOG_PRINT_GROUP ){
        len_preamb+=snprintf( buf + len_preamb, MAX_MESG_SIZE-1-len_preamb, "%s:", group);
    }
    if ( logMainInfo.flags & LOG_PRINT_FILE ){
        len_preamb+=snprintf(  buf + len_preamb, MAX_MESG_SIZE-1-len_preamb, "%s:", fname);
    }
    if ( logMainInfo.flags & LOG_PRINT_LINE ){
        len_preamb+=snprintf(  buf + len_preamb, MAX_MESG_SIZE-1-len_preamb, "%d:",  lineno);
    }
    len_mesg = vsnprintf( buf+len_preamb, MAX_MESG_SIZE-len_preamb-1 , str ,argptr);
    buf[len_preamb+len_mesg] = '\n';
    len = write( logMainInfo.writeBufDes, buf, len_preamb + len_mesg + 1);
    if ( len != len_preamb + len_mesg + 1 );
    return len+1;
}
	void CircleTrace::trace(double movement[])
	{
		// Initialize angle, translation, and rotation with the internal state
		double angle = this->movement[0];
		double translation = this->movement[1];
		double rotation = this->movement[2];

		double xTemp = 0.0;
		double yTemp = 0.0;
		double radius = 0.0;

		if(angle > M_PI)
		{
			angle -= TWO_PI;
		}


		// Check if this is the first call
		if(!this->isStopwatchStarted)
		{
			this->isStopwatchStarted = true;
			gettimeofday(&t0, 0);
		}
		else
		{
			gettimeofday(&t1, 0);
			double delta = ((double)timedifference_msec(t0, t1)) / 1000;
			gettimeofday(&t0, 0);

			translation *= delta;
			rotation *= delta;

			if(rotation != 0)
			{
				// The radius is given by ((2 * Pi * r) / (2 * Pi)) * t
				radius = abs(translation / rotation);
				// Get the projection of the radius
				xTemp = abs(sin(rotation) * radius) * geometry::sgn(translation);
				// The axis are rotated 90°!a
				yTemp = (radius - (cos(rotation)) * radius) * geometry::sgn(rotation);
			}
			else
			{
				xTemp = translation;
				yTemp = 0;
			}

			double h =  this->angle + angle;
			if(h > M_PI)
			{
				h -= TWO_PI;
			}

			double cos_h = cos(h);
			double sin_h = sin(h);
			double xTemp1 = cos_h * xTemp - sin_h * yTemp;
			double yTemp1 = sin_h * xTemp - cos_h * yTemp;

			this->angle += rotation;

			while(this->angle > M_PI)
			{
				this->angle -= TWO_PI;
			}
			// Adjust angle if it's < 0
			while(this->angle < -M_PI)
			{
				this->angle += TWO_PI;
			}

			this->x = xTemp1;
			this->y = yTemp1;
		}

		this->movement[0] = movement[0];
		this->movement[1] = movement[1];
		this->movement[2] = movement[2];
	}