Example #1
0
void alternateSize (int maxSize)
{
    int step = 500/maxSize, num = 0;
    for (int i = 0; i < maxSize; i++)
    {
        num = num + step;
        speedup (num, num, num, num, 5);
    }
}
Example #2
0
	void print_speedup(const measure_result_t& other) const {
		const auto s = speedup(other);

		if (s > 0.0)
			printf("faster %0.3f", s);
		else if (s < 0.0)
			printf("slower %0.3f", s);
		else
			printf("same speed");
	}
Example #3
0
void	Ncurses::display(std::list<t_snake> snake, const t_food food)
{
  wclear(_game);
  draw_border();
  for_each(snake.begin(), snake.end(), bind1st(std::mem_fun(&Ncurses::snake_body), this));
  snake_head(snake.begin()->x, snake.begin()->y);
  wattron(_game, COLOR_PAIR(1));
  mvwprintw(_game, food.y + 1, food.x + 1, "@");
  wattroff(_game, COLOR_PAIR(1));
  speedup(snake.begin()->x, snake.begin()->y, food.x, food.y);
  wrefresh(_game);
}
Example #4
0
int main()
{
    float res[4];
    float max[4];
    int ind[4];

    int i = 0;
    int j = 0;

    for (i = 0; i < 4; i++)
    {
	res[i] = 0;
	max[i] = 0;
	ind[i] = 0;
    }

    for (i = 0; i < 1024; i++)
    {
      res[0] = speedup(0.8, 1024, i, &perfA);
      res[1] = speedup(0.5, 1024, i, &perfA);
      res[2] = speedup(0.8, 1024, i, &perfB);
      res[3] = speedup(0.5, 1024, i, &perfB);

      for (j = 0; j < 4; j++)
      {
	if (res[j] > max[j])
	{
	    max[j] = res[j];
	    ind[j] = i;
	}
      }
    }

    for (i = 0; i < 4; i++)
    {
	printf("Result %d: Max. perf. @ R=%d, speedup is %f\n", i, ind[i], max[i]);
    }
}
Example #5
0
void memset_benchmark()
{
    // init some data
    int n = 1000000;
    QVector<int> v(n);

    auto memset_serial = [&]() {
        for (int i = 0; i < n; i++) {
            v[i] = i * i;
        }
    };

    auto memset_parallel = [&]() {
        #pragma omp parallel for
        for (int i = 0; i < n; i++) {
            v[i] = i * i;
        }
    };

    double memset_speedup = speedup(memset_serial, memset_parallel);
    qDebug() << "memset speedup:" << memset_speedup;
}
Example #6
0
int main()
{
  static uint16_t pulse_width;

  DDRB = 0;
  DDRD = 0;
  LED_DDR |= LED_BITS;			// LED pins out
  DDRB |= (1<<PB4);			// PWM out
  PORTD	= (1<<PD2)|(1<<PD3);		// pullups for sensors
  PORTB	= (1<<PB0)|(1<<PB1)|(1<<PB2);	// pullups for switches
  timer_init();
  hall_init();
  sei();			// enable interrupts.

  uint16_t pwm_stop_val = (PW_MIN+PW_MAX)/2+PW_TUNED_STOP;
  OCR1B	= pulse_width = pwm_stop_val;	// start stopped.

#define BAUD      19200
  rs232_init(UBRV(BAUD), &rs232_recv);

  uint16_t counter = 0;
  uint8_t paused = 0;
  uint8_t button_seen = 0;
  int16_t incr_counter = 0;

  for (;;)
    {
      if (!button_seen)
	{
	  if ((PINB & (1<<PB0)) || cmd_seen == '+' || cmd_seen == 'l')
	    {
	      if (!cmd_seen) button_seen = 1;
	      if (paused) 
	        {
		  pulse_width = pwm_stop_val;
		  incr_counter = 0;
		}
	      incr_counter++;
	      pulse_width = pwm_stop_val + speedup(incr_counter) * PW_BUT_INCR;
	      if (pulse_width > PW_MAX) pulse_width = PW_MAX;
	      paused = 0;
              rs232_send('l');
	    }
	  if ((PINB & (1<<PB2)) || cmd_seen == '-' || cmd_seen == 'r')
	    { 
	      if (!cmd_seen) button_seen = 1;
	      if (paused) 
	        {
		  pulse_width = pwm_stop_val;
		  incr_counter = 0;
		}
	      incr_counter--;
	      pulse_width = pwm_stop_val + speedup(incr_counter) * PW_BUT_INCR;
	      if (pulse_width < PW_MIN) pulse_width = PW_MIN;
	      paused = 0;
              rs232_send('r');
	    }
	  if ((PINB & (1<<PB1)) || cmd_seen == ' ')
	    {
	      if (!cmd_seen) button_seen = 1;
	      if (paused) 
	        {
		  paused = 0;
                  rs232_send('g');	  
		}
	      else 
	        {
		  paused = 1;
                  rs232_send('p');	  
		}
	    }
	}
      else
	{
	  // disable automatic key repeat
	  if (!(PINB & ((1<<PB0)|(1<<PB1)|(1<<PB2))))
	    button_seen = 0;	// need a release before press.
	  if (cmd_seen)
	    rs232_send('!');
	}

      if (paused)
        OCR1B = pwm_stop_val;
      else
        OCR1B = pulse_width;

      if (cmd_seen)
        {
	  cmd_seen = 0;	// very small race
          rs232_send_hex(pulse_width>>8);	  
          rs232_send_hex(pulse_width&0xff);	  
          rs232_send(' ');	  
          rs232_send_hex(hall_counter>>8);	  
          rs232_send_hex(hall_counter&0xff);	  
          rs232_send('\r');	  
          rs232_send('\n');	  
	}


      if (!(counter++ % 8))	// (1<<(led_what-1))))
        {
          _delay_ms(10.0); 
	  if (pulse_width > pwm_stop_val)
	    LED_PORT |=   GREEN_LED_BITS;         // pull high ...
	  if (pulse_width < pwm_stop_val)
	    LED_PORT |=   RED_LED_BITS;           // pull high ...
          _delay_ms(10.0);
	  if (paused) LED_PORT &= ~(LED_BITS);        // pull low ...
	  _delay_ms(80.0);
	  if (!paused) LED_PORT &= ~(LED_BITS);        // pull low ...
	}
      else
        {
	  _delay_ms(100.0);
	}
    }
}
Example #7
0
File: keyer.c Project: patlc/tlf
int keyer(void)
{

    extern char mode[20];
    extern int bufloc;
    extern char buffer[];
    extern char termbuf[];
    extern char message[15][80];
    extern char wkeyerbuffer[];
    extern int data_ready;
    extern int keyerport;
    extern int weight;

    int x = 0, i = 0, j = 0;
    int cury, curx;
    char nkbuffer[2];
    char keyerstring[30] = "                              ";
    char weightbuf[15];
    const char txcontrolstring[2] = { 20, '\0' };
    const char rxcontrolstring[2] = { 18, '\0' };
    const char crcontrolstring[2] = { 13, '\0' };
    const char ctl_c_controlstring[2] = { 92, '\0' };

    strcpy(mode, "Keyboard");
    clear_display();
    attron(COLOR_PAIR(C_LOG) | A_STANDOUT);

    if (keyerport == NO_KEYER)	/* no keyer present */
	return (1);

    if (keyerport == MFJ1278_KEYER) {
	buffer[0] = 20;		// 1 char at the time !
	buffer[1] = '\0';
	if (data_ready != 1) {
	    strcat(wkeyerbuffer, buffer);
	    data_ready = 1;
	}
	buffer[0] = '\0';
    }

    while (1) {
	x = onechar();

	if (x == 34) {		/* bug fix */// "
	    x = 32;
	}

	if (x == '\n')
	    x = 32;

	if (x == 27 || x == 11 || x == 235) {	//      esc, ctrl-k,  alt-k
	    if (keyerport == MFJ1278_KEYER) {
		buffer[0] = 18;	// 1 char at the time !
		buffer[1] = '\0';
		if (data_ready != 1) {
		    strcat(wkeyerbuffer, buffer);
		    data_ready = 1;
		}
	    } else {
		stoptx();
	    }

	    buffer[0] = '\0';
	    break;
	}

	if (x >= 32 && x <= 125) {	// display              space ... }
	    addch(x);
	    refreshp();
	    i++;
	    if ((i >= 40)) {
		i = 0;
		mvprintw(4, 0, "                            ");
		mvprintw(4, 0, "");
		refreshp();
		displayit();

	    }

	    refreshp();
	}

	if (x == 127 && (strlen(buffer) >= 1)) {	/* erase  */

	    getyx(stdscr, cury, curx);
	    mvprintw(5, curx - 1, " ");
	    mvprintw(5, curx - 1, "");
	    buffer[strlen(buffer) - 1] = '\0';
	    bufloc--;
	}

	if (x > 96 && x < 123)	/* upper case only */
	    x = x - 32;

	if (x > 9 && x < 91) {

	    if (bufloc >= 38)	// maximum buffer = 39
	    {
		bufloc = 38;
		printw("\nBuffer overflow !, bufloc = %d\n", bufloc);
		refreshp();
	    } else {
		if (x > 31 || x == 10) {
		    if (keyerport == MFJ1278_KEYER) {
			mfj1278_control(x);
		    } else if (keyerport == NET_KEYER) {
			nkbuffer[0] = x;	// 1 char at the time !
			nkbuffer[1] = '\0';
			netkeyer(K_MESSAGE, nkbuffer);
			nkbuffer[0] = '\0';
			for (j = 0; j < 29; j++) {
			    keyerstring[j] = keyerstring[j + 1];
			}
			keyerstring[28] = x;
			keyerstring[29] = '\0';

			attron(COLOR_PAIR(C_LOG) | A_STANDOUT);
			mvprintw(5, 0, "%s", keyerstring);
			refreshp();
		    } else if (keyerport == ORION_KEYER) {
			nkbuffer[0] = x;
			nkbuffer[1] = '\0';
			strcat(wkeyerbuffer, nkbuffer);
			sendbuf();
			nkbuffer[0] = '\0';
			for (j = 0; j < 29; j++) {
			    keyerstring[j] = keyerstring[j + 1];
			}
			keyerstring[28] = x;
			keyerstring[29] = '\0';

			attron(COLOR_PAIR(C_LOG) | A_STANDOUT);
			mvprintw(5, 0, "%s", keyerstring);
			refreshp();

		    }
		} else		// control char...
		{

		    if (data_ready != 1) {
			strcat(wkeyerbuffer, buffer);
			data_ready = 1;
		    } else
			buffer[0] = '\0';

		    getyx(stdscr, cury, curx);
		    attron(COLOR_PAIR(C_HEADER) | A_STANDOUT);
		    mvaddstr(0, 0, "  ");
		    attron(COLOR_PAIR(C_LOG));
		    mvaddstr(cury, curx, "");
		    refreshp();

		    strcat(termbuf, buffer);
		    strcat(termbuf, " ");
		    mvprintw(5, 0, termbuf);
		    refreshp();

		    if ((strlen(buffer) + strlen(termbuf) > 39)
			|| x == '=') {
			i = 0;
			mvprintw(5, 0, "                         ");
			mvprintw(5, 0, "");
			refreshp();
			displayit();
		    }

		    bufloc = 0;
		    buffer[bufloc] = '\0';
		}
	    }
	} else {

	    switch (x) {
	    case 9:
		{
		    bufloc = 0;
		    buffer[bufloc] = '\0';
		    strcpy(mode, "Log     ");
		    clear_display();
		    return (2);
		}
	    case '\n':
	    case 13:
		{
		    if (keyerport == MFJ1278_KEYER && strlen(buffer) < 39) {
			strcat(buffer, crcontrolstring);
			sendbuf();
			bufloc = 0;
		    }
		    break;
		}

	    case 27:
	    case 11:
		{
		    stoptx();
		    bufloc = 0;
		    buffer[bufloc] = '\0';
		    strcpy(mode, "Log     ");
		    clear_display();
		    return (2);
		}
	    case 123:
		{
		    if (keyerport == MFJ1278_KEYER) {
			strcat(buffer, txcontrolstring);
			sendbuf();
		    }
		    break;
		}
	    case 125:
		{
		    if (keyerport == MFJ1278_KEYER) {
			strcat(buffer, rxcontrolstring);
			sendbuf();
		    }
		    break;
		}
	    case 92:
		{
		    if (keyerport == MFJ1278_KEYER) {
			strcat(buffer, ctl_c_controlstring);
			sendbuf();
		    }
		    break;
		}

	    case 247:		// Alt-w, set weight
		{
		    mvprintw(1, 0, "Weight=   ");
		    mvprintw(1, 7, "");
		    refreshp();
		    echo();
		    getnstr(weightbuf, 2);
		    noecho();

		    weight = atoi(weightbuf);
		    netkeyer(K_WEIGHT, weightbuf);
		    break;
		}
	    case 156:
		{
		    speedup();
		    clear_display();
		    break;
		}
	    case 157:
		{
		    speeddown();
		    clear_display();
		    break;
		}

	    case 129:
		{
		    strcat(buffer, message[0]);	/* F1 */
		    getyx(stdscr, cury, curx);
		    mvprintw(5, 0, "");
		    sendbuf();
		    mvprintw(cury, curx, "");
		    break;
		}
	    case 130:
		{
		    strcat(buffer, message[1]);	/* F2 */
		    sendbuf();
		    break;
		}
	    case 131:
		{
		    strcat(buffer, message[2]);	/* F3 */
		    sendbuf();
		    break;
		}
	    case 132:
		{
		    strcat(buffer, message[3]);	/* F4 */
		    sendbuf();
		    break;
		}
	    case 133:
		{
		    strcat(buffer, message[4]);	/* F5 */
		    sendbuf();
		    break;
		}
	    case 134:
		{
		    strcat(buffer, message[5]);	/* F6 */
		    sendbuf();
		    break;
		}
	    case 135:
		{
		    strcat(buffer, message[6]);	/* F7 */
		    sendbuf();
		    break;
		}
	    case 136:
		{
		    strcat(buffer, message[7]);	/* F8 */
		    sendbuf();
		    break;
		}
	    case 137:
		{
		    strcat(buffer, message[8]);	/* F9 */
		    sendbuf();
		    break;
		}
	    case 138:
		{
		    strcat(buffer, message[9]);	/* F10 */
		    sendbuf();
		    break;
		}

	    case 140:
		{
		    strcat(buffer, message[10]);	/* F11 */
		    sendbuf();
		    break;
		}
	    case 141:
		{

		    strcat(buffer, message[11]);	/* F12 */
		    sendbuf();
		    break;
		}

	    default:
		x = x;
	    }

	}
    }

    strcpy(mode, "Log     ");
    clear_display();

    return (2);			/* show end of keyer  routine */
}
Example #8
0
int keyer(void)
{

    extern int cqmode;
    extern char mode[20];
    extern char message[][80];
    extern char wkeyerbuffer[];
    extern int data_ready;
    extern int keyerport;
    extern int weight;

    WINDOW *win = NULL;
    PANEL *panel = NULL;

    int x = 0, j = 0;
    int cury, curx;
    char nkbuffer[2];
    char keyerstring[KEYER_LINE_WIDTH+1] = "";
    int keyerstringpos = 0;
    char weightbuf[15];
    const char txcontrolstring[2] = { 20, '\0' };	// ^t
    const char rxcontrolstring[2] = { 18, '\0' };	// ^r
    const char crcontrolstring[2] = { 13, '\0' };	// cr
    const char ctl_c_controlstring[2] = { 92, '\0' };	// '\'

    if (keyerport == NO_KEYER)	/* no keyer present */
	return 1;

    strcpy(mode, "Keyboard");
    clear_display();
    attron(COLOR_PAIR(C_LOG) | A_STANDOUT);

    if (panel == NULL) {
	win = newwin(KEYER_WIN_HEIGHT, KEYER_WIN_WIDTH, KEYER_Y, KEYER_Y );
	if (win == NULL)
	    return 1;
	panel = new_panel(win);
	if (panel == NULL) {
	    delwin(win);
	    return 1;
	}
    }

    show_panel(panel);
    werase(win);
    wnicebox(win, 0, 0, 1, KEYER_LINE_WIDTH, "CW Keyer");

    if (keyerport == MFJ1278_KEYER) {
	if (data_ready != 1) { 		/* switch to tx */
	    strcat(wkeyerbuffer, txcontrolstring);
	    data_ready = 1;
	}
    }

    while (1) {
	wattron(win, COLOR_PAIR(C_LOG) | A_STANDOUT);
	wmove (win, 1, 1);
	for (j = 0; j < KEYER_LINE_WIDTH; j++) {
	    waddch (win, ' ');
	}
	mvwprintw(win, 1, 1, "%s", keyerstring);
	refreshp();

	x = key_get();

	// Send space instead of double quote.
	if (x == 34) {
	    x = 32;
	}

	// Send space instead of newline or return.
	if (x == '\n' || x == KEY_ENTER)
	    x = 32;

	// <Escape>, Ctrl-K (^K), Alt-k (M-k)
	if (x == 27 || x == 11 || x == 235) {
	    if (keyerport == MFJ1278_KEYER) {
		if (data_ready != 1) { 	/* switch back to rx */
		    strcat(wkeyerbuffer, rxcontrolstring);
		    data_ready = 1;
		}
	    } else {
		stoptx();
	    }

	    break;
	}

	// Promote lower case to upper case.
	if (x > 96 && x < 123)
	    x = x - 32;

	if (x > 9 && x < 91) { 	/* drop all other control char... */
	    if (x > 31 || x == 10) {
		if (keyerport == MFJ1278_KEYER) {
		    mfj1278_control(x);
		} else if (keyerport == NET_KEYER) {
		    nkbuffer[0] = x;	// 1 char at the time !
		    nkbuffer[1] = '\0';
		    netkeyer(K_MESSAGE, nkbuffer);
		}

		/* if display field is full move text one left */
		if (keyerstringpos == KEYER_LINE_WIDTH - 1) {
		    for (j = 0; j < KEYER_LINE_WIDTH - 1; j++) {
		    	keyerstring[j] = keyerstring[j + 1];
		    }
		    keyerstringpos--;
		}
		/* add new character for display */
		keyerstring[keyerstringpos++] = x;
		keyerstring[keyerstringpos] = '\0';
	    }
	} else {

	    switch (x) {
	    case '\n':
	    case 13:
	    case KEY_ENTER:
		{
		    if (keyerport == MFJ1278_KEYER) {
			sendmessage(crcontrolstring);
		    }
		    break;
		}

	    case 123:		/* { */
		{
		    if (keyerport == MFJ1278_KEYER) {
			sendmessage(txcontrolstring);
		    }
		    break;
		}
	    case 125:		/* } */
		{
		    if (keyerport == MFJ1278_KEYER) {
			sendmessage(rxcontrolstring);
		    }
		    break;
		}
	    case 92:		/* \ */
		{
		    if (keyerport == MFJ1278_KEYER) {
			sendmessage(ctl_c_controlstring);
		    }
		    break;
		}

	    case 247:		// Alt-w, set weight
		{
		    mvprintw(1, 0, "Weight=   ");
		    mvprintw(1, 7, "");
		    refreshp();
		    echo();
		    getnstr(weightbuf, 2);
		    noecho();

		    weight = atoi(weightbuf);
		    netkeyer(K_WEIGHT, weightbuf);
		    break;
		}

	    // <Page-Up>, increase CW speed.
	    case KEY_PPAGE:
		{
		    speedup();
		    clear_display();
		    break;
		}

	    // <Page-Down>, decrease CW speed.
	    case KEY_NPAGE:
		{
		    speeddown();
		    clear_display();
		    break;
		}

	    case KEY_F(1):
		{
		    getyx(stdscr, cury, curx);
		    mvprintw(5, 0, "");
		    sendmessage(message[0]);	/* F1 */
		    mvprintw(cury, curx, "");
		    break;
		}
	    case KEY_F(2):
		{
		    sendmessage(message[1]);	/* F2 */
		    break;
		}
	    case KEY_F(3):
		{
		    sendmessage(message[2]);	/* F3 */
		    break;
		}
	    case KEY_F(4):
		{
		    sendmessage(message[3]);	/* F4 */
		    break;
		}
	    case KEY_F(5):
		{
		    sendmessage(message[4]);	/* F5 */
		    break;
		}
	    case KEY_F(6):
		{
		    sendmessage(message[5]);	/* F6 */
		    break;
		}
	    case KEY_F(7):
		{
		    sendmessage(message[6]);	/* F7 */
		    break;
		}
	    case KEY_F(8):
		{
		    sendmessage(message[7]);	/* F8 */
		    break;
		}
	    case KEY_F(9):
		{
		    sendmessage(message[8]);	/* F9 */
		    break;
		}
	    case KEY_F(10):
		{
		    sendmessage(message[9]);	/* F10 */
		    break;
		}

	    case KEY_F(11):
		{
		    sendmessage(message[10]);	/* F11 */
		    break;
		}
	    case KEY_F(12):
		{

		    sendmessage(message[11]);	/* F12 */
		    break;
		}

	    default:
		x = x;
	    }

	}
    }
    hide_panel(panel);

    if (cqmode == CQ)
        strcpy(mode, "Log     ");
    else
        strcpy(mode, "S&P     ");

    clear_display();

    return 0;			/* show end of keyer  routine */
}