예제 #1
0
int main(void)
{
    int value1;
    int value2;
    int value3;
    int *no1;
    int *no2;
    int *no3;
    void sort_int( int *no1, int *no2, int *no3);

    printf("Enter No. 1: ");
    scanf("%d", &value1);
    printf("Enter No. 2: ");
    scanf("%d", &value2);
    printf("Enter No. 3: ");
    scanf("%d", &value3);

    printf("\nBefore Sorting \n");
    printf("Value 1 %d\n", value1);
    printf("Value 2 %d\n", value2);
    printf("Value 3 %d\n", value3);

    sort_int( &value1, &value2, &value3);

    printf("\nAfter Sorting \n");
    printf("Value 1 %d\n", value1);
    printf("Value 2 %d\n", value2);
    printf("Value 3 %d\n", value3);

    getch();
}
예제 #2
0
void ProbeTimer() // 获取本机最小能计时的时间精度
{
    int probe[NUM_TIMER_PROBING];
    int i;
    struct timeval sleep_time, time[NUM_TIMER_PROBING] ;
    
    // 获取Select可以精确的时间精度
    gettimeofday(&time[0], NULL);
    for(i=1; i<NUM_TIMER_PROBING; i++)
    {
        sleep_time.tv_sec = 0;
        sleep_time.tv_usec = 1;
        select(0,NULL,NULL,NULL,&sleep_time);  // 睡眠1 usec
        gettimeofday(&time[i], NULL);          // 获取苏醒时间,看最低精确到多少
    }
    
    for(i=1; i<NUM_TIMER_PROBING; i++)
    {
        probe[i-1] = (time[i].tv_sec - time[i-1].tv_sec) * 1000000 +
        (time[i].tv_usec - time[i-1].tv_usec);
    }
    
    sort_int(probe, NUM_TIMER_PROBING - 1);  // 排序

    timer_resolution = (probe[NUM_TIMER_PROBING/2]+probe[NUM_TIMER_PROBING/2+1])/2; //取中位值
    if (debug == 1)
        printf("INFO:The timer resolution is %d usecs.\n", timer_resolution);
    
    // 获取gettimeofday的时间精度
    gettimeofday(&time[0], NULL);
    for(i=1; i<NUM_TIMER_PROBING; i++)
    {
        gettimeofday(&time[i], NULL);          
        probe[i-1] = (time[i].tv_sec - time[i-1].tv_sec) * 1000000 +
        (time[i].tv_usec - time[i-1].tv_usec);
    }
    
    sort_int(probe, NUM_TIMER_PROBING - 1); 
    gettimeofday_resolution = (probe[NUM_TIMER_PROBING/2]+probe[NUM_TIMER_PROBING/2+1])/2;
    if (debug == 1)
        printf("INFO:The gettimeofday resolution is %d usecs.\n", gettimeofday_resolution);
    
} // end ProbeTimer()
예제 #3
0
static void test_sort()
{
    int array[] = { 4, 3, 7, 5, 2, 5, 1, 2, 9, 6, 7, 4, 5, 3, 1, 0 };
    int* ptr[SK_ARRAY_COUNT(array)];
    int i, N = SK_ARRAY_COUNT(array) - 1;

    for (i = 0; i < N; i++)
        printf(" %d", array[i]);
    printf("\n");
    
    for (i = 0; i < N; i++)
        ptr[i] = &array[i];
    sort_intptr(ptr, N);
    for (i = 0; i < N; i++)
        printf(" %d", *ptr[i]);
    printf("\n");

    sort_int(array, N);
    for (i = 0; i < N; i++)
        printf(" %d", array[i]);
    printf("\n");

}
예제 #4
0
double ProcessPT (int i_PktNumb)
{
  int i=0, count=0, expected = 0, loss=0;
  double at[MAX_PKT_NUM], invalidrate, lossrate;
  int sum = 0;
  double medianAt=0., meanAt=0.;
  double medianAb=0., meanAb=0.;

  for (i=0; i<i_PktNumb; i++) 
    {
      if (seq[i] != expected) // Sequence number is not the one we expected (out of order=loss)
	{
	  printf ("[%2d](%2d-%2d): Dispersion invalid due to packet #%d lost (match 1)! \n", 
		  expected, expected, expected+1, expected); // the expected packet is lost
	  loss++;
	  if (seq[i] > expected) // Bursty loss
	    {
	      expected++;
	      while (seq[i] > expected && expected < i_PktNumb) 
		{
		  printf ("[%2d](%2d-%2d): Dispersion invalid due to packet #%d lost (match 2)! \n", 
			  expected, expected, expected+1, expected); // more losses after the first loss
		  loss++;
		  expected++;
		}
	    }
	}
      
      if (seq[i+1] == seq[i] + 1 && seq[i] == expected) // Good pkts, count the total good ones
	{
	  disperse[count] = (arrival[i+1].tv_sec - arrival[i].tv_sec) * 1000000 +
	    (arrival[i+1].tv_usec - arrival[i].tv_usec);

	  
	  at[count] = (psize[i+1]*8.0/disperse[count]);              // compute achievable throughput
	  sr[count] = psize[i+1]*8.0/(sendtime[i+1]-sendtime[i]);    // compute sending rate
          // dispersion rate should less than sending rate
	  if (at[count] > sr[count]) disperse[count] = psize[i+1]*8.0/sr[count];          

	  sum += disperse[count]; 

	  // Todo: maybe we need to filter out these sending error -- if (sr < ce) => discard?
	  
	  printf("[%2d](%2d-%2d): %d recv in %d usec - At: %7.2f Mbps, sendRate: %7.2f Mbps\n", 
		 expected, expected, expected+1, psize[i+1], disperse[count], at[count], sr[count]);
	  count++;
	}
      else // expected packet is good, however, the next one lost
	{
	  printf ("[%2d](%2d-%2d): Dispersion invalid due to packet #%d lost (next 1)! \n", 
		  expected, expected, expected+1, expected+1); // the next one packet is lost
	  if (expected == i_PktNumb -2) loss++; // Last packet in the train is lost... 
	}
      expected ++;
      if (expected >= i_PktNumb -1) break;
    }

  // in general, one packet loss = two dispersion loss
  // Todo: we can estimate the bursty loss be compare lossrate and invalidrate.
  //
  lossrate = (double)loss/(double)i_PktNumb;                            // loss rate of pkt
  invalidrate = (double)(i_PktNumb - 1 - count)/(double)(i_PktNumb-1);  // loss rate of dispersion

  printf("Summary of At test with %d valid tests out %d train (%d tests):\n",
         count, i_PktNumb, i_PktNumb - 1);
  printf("\tpacket loss: %d (%f%%) \n\tinvalid result: %d (%f%%)\n",
	 loss, lossrate * 100, i_PktNumb - 1 - count, invalidrate * 100);

  sort_int(disperse, count);
  
  meanAt = (double)psize[0] * 8.0 / ((double)sum / (double)count);
  medianAt = (double)psize[0] * 8.0 / (((double)disperse[count/2] + (double)disperse[count/2+1]) / 2.0);
  //printf("\tmean At: %f Mbps\n\tmedian At: %f Mbps\n", meanAt, medianAt);
  printf("\tmean At: %f Mbps\n", meanAt);

  // Equations... need to play around to compare the performance.
  // And to return At if the At is less than half Ce
  if (meanAt >= allCE ) 
    {
       meanAb = meanAt;
    }
  else
    {
      meanAb = allCE * (2.0 - allCE/meanAt);
    }

  
  if (medianAt >= allCE )
    {
       medianAb = medianAt;
    }
  else
    {
      medianAb = allCE * (2.0 - allCE/medianAt);
    }
  /*
  printf("\tmean Ab: %f Mbps\n\tmedian Ab: %f Mbps\n", meanAb, medianAb);
  printf("\tmean Ab with loss: %f Mbps\n\tmedian Ab with loss: %f Mbps\n", meanAb*(1.0-lossrate), medianAb*(1.0-lossrate));
  */

  printf("\tmean Ab: %f Mbps\n", meanAb);
  printf("\tmean Ab with loss: %f Mbps\n", meanAb*(1.0-lossrate));

  if (meanAb < 0) 
    {
      return 0; 
    }
  else 
    {
      return meanAb*(1.0-lossrate);
    }
      
} // end ProcessPT()