All pastes #36780 Raw Edit

mikeX

public c v1 · immutable
#36780 ·published 2006-01-14 15:25 UTC
rendered paste body
#include <stdio.h>#include <stdarg.h>#include <sys/time.h>#include <time.h>inline void dprint(const char *fmt, ...);int main(int argc, char **argv){	struct timeval *start, *finish;	suseconds_t usec;	time_t secs;	long row = 1024, col = 512, x, y;			start  = (struct timeval*) malloc(sizeof(struct timeval));	finish = (struct timeval*) malloc(sizeof(struct timeval));		if (argc > 1) {		row = strtol(argv[1], NULL, 10);		if (argc > 2)			col = strtol(argv[2], NULL, 10);	}					double tab[row][col];	gettimeofday(start, NULL);		for (x = 0; x < row; x++)		for (y = 0; y < col; y++)			tab[x][y] = 1.0;	for (x = 0; x < row; x++) {		for (y = 0; y < col; y++) {			if (x > 2 && y > 2)				tab[x][y] += tab[x-1][y] + tab[x-2][y] + tab[x][y-1] + tab[x][y-2];			dprint("tab[%05u][%05u]: %50.1f\n", x, y, tab[x][y]);		}	}	gettimeofday(finish, NULL);	secs = finish->tv_sec - start->tv_sec;	usec = finish->tv_usec - start->tv_usec;	free(finish);	free(start);	printf("time: %3ds %10llus\n", secs, usec);	fflush(stdout);		return 0;}inline voiddprint(const char *fmt, ...){#ifdef DEBUG	va_list ap;	va_start(ap, fmt);	vfprintf(stderr, fmt, ap);	va_end(ap);#endif}