示例#1
0
int main(int argc, char *argv[])
{
	if(argc < 2){
		printf("err input\n./simple_test 1 or ./simple_test 30\n");
		return -1;
	}
	muduo_clog_init("simple_test_fake");

	int i = 0, j = 0;
	struct timespec old_tp, new_tp, out_tp;
	for(j = 0; j < atoi(argv[1]); j++){	
		clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &old_tp);
		for(i = 0; i < LOG_WRITE_NUM; i++){
			MUDUO_CLOG_TRACE("1234567890 abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGH");
			MUDUO_CLOG_DEBUG("1234567890 abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGH");
			MUDUO_CLOG_INFO("1234567890 abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGH");
			MUDUO_CLOG_WARN("1234567890 abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGH");
			MUDUO_CLOG_ERROR("1234567890 abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGH");
//			MUDUO_CLOG_SYSFATAL("1234567890 abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGH");
		}
		clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &new_tp);
		get_time_gap(&old_tp, &new_tp, &out_tp);
		printf("inner : %ld.%09ld, per: %ld(ns)\n", out_tp.tv_sec, out_tp.tv_nsec, (out_tp.tv_sec * 1000000000 + out_tp.tv_nsec)/ LOG_WRITE_NUM);
	}
	printf("total %ld.%09ld\n", new_tp.tv_sec, new_tp.tv_nsec);
	return 0;
}
示例#2
0
int main(int argc, char *argv[])
{	
	//initializing
	initscr(); 				//starts ncurses			
	cbreak();				//allows input to be accessed as soon as it is typed without having to press the 'enter' key		
	keypad(stdscr, TRUE); 	//allows arrow keys and F1,F2,etc to be read
	noecho();   			//does not echo the typed characters on the screen
	curs_set(0); 			//does not display the curser
	start_color();  		//starts colour functionality
	
	
	start_screen();			//calls the start screen function (in start_end_screen.c)
	
	//variable declaration
	WINDOW *my_win,*enemy_win;
	int startx, starty;
	int ch,end_game=0,first_time=1;
	int score=0;
	time_t t;
	//seed the random function
	srand((unsigned) time(&t));
		
	//initial placement of player is in the centre of the screen
	starty = (LINES) / 2;	
	startx = (COLS) / 2;	
	refresh();
	//create player
	my_win = create_playerwin(starty, startx);
	
	
	//this is to space out the enemies to be dropped and make sure that even if a value for getchar() isnt enetered the game loop continues. i.e. enemies continue to be dropped. - but remember with just this, the game will do a loop without this delay if the player gives an input in less than 0.5 seconds. So this case is handled later. Lets call it 'case1'. . 
	/* So if this is changed for difficulty also correspondingly change the place where case1 is handled where get_time_gap() is called in main*/
	halfdelay(5);	//this waits for 0.5 seconds for an input, if no input is given, it skips the scan statement and continues the program
	
	//game loop - ch holds the currently entered button
	while((ch = getch()) != 'q')
	{	
		//for movement - the player window is destroyed and recreated at the new position
		switch(ch)
		{	case KEY_LEFT:
				if (startx==0) //left side boundary for player
				{
					break;
				}
				destroy_win(my_win);
				my_win = create_playerwin(starty,--startx);
				break;
			case KEY_RIGHT:
				if (startx>=COLS-6)  //right side boundary for the player (the -6 is to account for the size of the player object)
				{
					break;
				}
				destroy_win(my_win);
				my_win = create_playerwin(starty,++startx);
				break;
			case KEY_UP:
				if (starty==1)  //top boundary for the player
				{
					break;
				}
				destroy_win(my_win);
				my_win = create_playerwin(--starty,startx);
				break;
			case KEY_DOWN:   //bottom boundary for the player (the -4 is to account for the size of the player object)
				if (starty==LINES-4)
				{
					break;
				}
				destroy_win(my_win);
				my_win = create_playerwin(++starty,startx);
				break;
			//pausing the game
			case 'p':
				cbreak();
				mvprintw(0,0,"Press any key to resume. SCORE: %d           ",score);
				getch();
				halfdelay(5);
				break;
		}
		
		//for the first time the time must be set (the time at the previous instant when the enemy was dropped is recorded and the time elapsed since then is checked. If it reaches 0.5 seconds, it drops the next enemy)
		if (first_time==1)
		{
			first_time=0;
			gettimeofday(&time1,NULL);
		}
		gettimeofday(&time2,NULL);
		
		//print important game statistics and instructions
		mvprintw(0,0,"Press 'q' to quit. 'p' to pause. SCORE: %d",score);
		
		//this condition is to ensure that the game loop waits for 0.5 sec before executing again in the situation that the player has entered an input quickly. It takes care of 'case1'
	/* So if this is changed for difficulty, also correspondingly change the place where case1 was mentioned in the half_delay function*/
		if (get_time_gap()<500000.0) 
		{
			continue;
		}
		//end game becomes 1 if you have been hit
		end_game=drop_enemy(&score,starty,startx);
		if (end_game==1)
		{
			break; //breaks the game loop
		}
		gettimeofday(&time1,NULL);
	}
	//call the high scores screen (in start_end_screen.c)
	high_scores(score);	
	endwin();
	/* End curses mode */			
	return 0;
}