Example #1
0
int main(int argc, char *argv[]) {
  char from[1000] = {'a'};
  char to[1000] = {'c'};
  int rc = 0;

  // setup the from to have some stuff
  memset(from, 'x', 1000);
  // set it to a failure mode
  memset(to, 'y', 1000);
  check(valid_copy(to, 1000, 'y'), "Not initialized right.");

  // use normal copy to 
  rc = normal_copy(from, to, 1000);
  check(rc == 1000, "Normal copy failed: %d", rc);
  check(valid_copy(to, 1000, 'x'), "Normal copy failed.");

  // reset
  memset(to, 'y', 1000);

  // duffs version
  rc = duffs_device(from, to, 1000);
  check(rc == 1000, "Duff's device failed: %d", rc);
  check(valid_copy(to, 1000, 'x'), "Duff's device failed copy.");

  // reset
  memset(to, 'y', 1000);

  // my version
  rc = zeds_device(from, to, 1000);
  check(rc == 1000, "Zed's device failed: %d", rc);
  check(valid_copy(to, 1000, 'x'), "Zed's device failed copy.");

  const int length = 10;
  char from2[length] = {'a'};
  char to2[length] = {'c'};
  int rc2 = 0;

  memset(from2, 'x', length);
  memset(to, 'y', length);

  rc2 = duffs_device(from2, to2, length);
  check(rc2 == length, "Duff's device failed: %d", rc2);
  check(valid_copy(to2, length, 'x'), "Duff's device failed copy.");

  return 0;
error:
  return 1;
}
Example #2
0
int main(int argc, char *argv[]) {
    char from[1000] = {'a'};
    char to[1000] = {'c'};
    int rc = 0;

    memset(from, 'x', 1000);
    memset(to, 'y', 1000);
    check(valid_copy(to, 1000, 'y'), "Not initialized right.");

    rc = normal_copy(from, to, 1000);
    check(rc == 1000, "Normal copy failed: %d", rc);
    check(valid_copy(to, 1000, 'x'), "Normal copy failed");

    memset(to, 'y', 1000);
    
    rc = duffs_device(from, to, 1000);
    check(rc == 1000, "Duff's device failed: %d", rc);
    check(valid_copy(to, 1000, 'x'), "Duff's device failed copy.");

    memset(to, 'y', 1000);

    rc = zeds_device(from, to, 1000);
    check(rc == 1000, "Zed's device failed: %d", rc);
    check(valid_copy(to, 1000, 'x'), "Zed's device failed copy.");

    return 0;
error:
    return 1;
}
Example #3
0
int main(int argc, char **argv)
{
	char from[1000] = { 'a' };
	char to[1000] = { 'a' };
	int rc = 0, i = 0;
	double accumulate_time = 0.0;
	clock_t begin, end;

	// set up the from to have some stuff
	memset(from, 'x', 1000);
	// set it to a failure mode
	memset(to, 'y', 1000);
	check(valid_copy(to, 1000, 'y'), "Not initialised right.");

	// use normal copy to
	begin = clock();
	for (i = 0; i < ITERATE_TIMES; i++) {
		rc = normal_copy(from, to, 1000);
	}
	end = clock();
	accumulate_time = (double)(end - begin);
	check(rc == 1000, "Normal copy failed: %d", rc);
	check(valid_copy(to, 1000, 'x'), "Normal copy failed.");
	printf("The time period of normal_copy is %lf ms(average run %d times)\n",
			 accumulate_time / ITERATE_TIMES, ITERATE_TIMES);

	// reset
	memset(to, 'y', 1000);

	// duffs version
	begin = clock();
	for (i = 0; i < ITERATE_TIMES; i++) {
		rc = duffs_device(from, to, 1000);
	}
	end = clock();
	accumulate_time = (double)(end - begin);
	check(rc == 1000, "Duff's device failed: %d", rc);
	check(valid_copy(to, 1000, 'x'), "Duff's device failed copy.");
	printf("The time period of duffs_device_copy is %lf ms(average run %d times)\n",
			 accumulate_time / ITERATE_TIMES, ITERATE_TIMES);

	// reset
	memset(to, 'y', 1000);

	// my version
	begin = clock();
	for (i = 0; i < ITERATE_TIMES; i++) {
		rc = zeds_device(from, to, 1000);
	}
	end = clock();
	accumulate_time = (double)(end - begin);
	check(rc == 1000, "Zed's device failed: %d", rc);
	check(valid_copy(to, 1000, 'x'), "Zed's device failed copy.");
	printf("The time period of zeds_device_copy is %lf ms(average run %d times)\n",
			 accumulate_time / ITERATE_TIMES, ITERATE_TIMES);

	return 0;
error:
	return 1;
}
Example #4
0
int main(int argc, char *argv[])
{
    char from[MAX_SIZE] = { 'a' };
    char to[MAX_SIZE] = { 'c' };
    int rc = 0;

    debug("Starting");
    // set up the from to have some stuff
    debug("Set up from");
    memset(from, 'x', MAX_SIZE);
    print_chars(from, MAX_SIZE);
    // set it to a failure mode
    debug("Set up to");
    memset(to, 'y', MAX_SIZE);
    print_chars(to, MAX_SIZE);
    check(valid_copy(to, MAX_SIZE, 'y'), "Not initialized correctly");

    // use normal copy to
    rc = normal_copy(from, to, MAX_SIZE);
    check(rc == MAX_SIZE, "Normal copy failed: %d", rc);
    check(valid_copy(to, MAX_SIZE, 'x'), "Normal copy failed");

    // reset
    memset(to, 'y', MAX_SIZE);
    debug("From: ");
    print_chars(from, MAX_SIZE);
    debug("To: ");
    print_chars(to, MAX_SIZE);
    rc = duffs_device(from, to, MAX_SIZE);
    debug("Duffs - From: ");
    print_chars(from, MAX_SIZE);
    debug("Duffs - To: ");
    print_chars(to, MAX_SIZE);

    debug("Duff's value: %d", rc);
    check(rc == MAX_SIZE, "Duff's device failed: %d", rc);
    check(valid_copy(to, MAX_SIZE, 'x'), "Duff's device copy failed");

    // reset
    memset(to, 'y', MAX_SIZE);

    // zed shaw's version
    debug("From: ");
    print_chars(from, MAX_SIZE);
    debug("To: ");
    print_chars(to, MAX_SIZE);
    rc = zeds_device(from, to, MAX_SIZE);
    debug("Zed - From: ");
    print_chars(from, MAX_SIZE);
    debug("Zed - To: ");
    print_chars(to, MAX_SIZE);    debug("Zed's value: %d", rc);
    check(rc == MAX_SIZE, "Zed's device failed: %d", rc);
    check(valid_copy(to, MAX_SIZE, 'x'), "Zed's device failed copy");

    debug("Finishing");
    return 0;
error:
    return 1;
}
Example #5
0
File: ex23.c Project: Faur/LcTHW
int main(int argc, char **argv){
	char from[LEN] = {'a'};
	char to[LEN] = {'c'};
	int rc = 0;

	//setup the from to have some stuff
	memset(from, 'x', LEN);
	memset(to, 'y', LEN);
	check(valid_copy(to, LEN, 'y'), "Not initialized right.");

	//USE: normal copy
	puts("Norm");
//	clock_t t0 = clock();
	memset(to, 'y', LEN);
	rc = normal_copy(from, to, LEN);
	check(rc == LEN, "Normal copy failed: %d.", rc);
	check(valid_copy(to, LEN, 'x'), "Normal copy failed.");

//	long double t_elapsed = (clock() - t0)/CLOCKS_PER_SEC;
//	printf("Time elapsed, Norm: %Le\n", t_elapsed);

	/*Reset*/	
	memset(to, 'y', LEN);
	//duffs version
	puts("Duff");
	rc = duffs_device(from, to, LEN);
	check(rc == LEN, "Duff's device failed: %d.", rc);
	check(valid_copy(to, LEN, 'x'), "Duff's device failed.");

	/*Reset*/	
	memset(to, 'y', LEN);
	//Zeds version
	puts("Zed");
	rc = zeds_device(from, to, LEN);
	check(rc == LEN, "Zed's device failed: %d.", rc);
	check(valid_copy(to, LEN, 'x'), "Zed's deice failed.");

	
	puts("Toke");
	memset(to, 'y', LEN);
	//Tokes version
	rc = 0;
	{
		char *to2 = to;
		char *from2 = from;
		while((*to2++ = *from2++), rc++<LEN-1);
	}
	check(rc == LEN, "Toke's device failed: %d.", rc);
	check(valid_copy(to, LEN, 'x'), "Toke's device failed.");
	/**/

	return 0;

error:
	return 1;

}
Example #6
0
File: ex23.c Project: jradix/lcthw
int main(int argc, char *argv[])
{
  char from[1000] = {'a'};
  char to[1000] = {'c'};
  int rc = 0;

  // setup the from to have some stuff
  memset(from, 'x', 1000);
  // set it to a failure
  memset(to, 'y', 1000);
  check(valid_copy(to, 1000, 'y'), "Not initialized right.");

  clock_t start, finish;

  // use normal copy to
  start = clock();
  rc = normal_copy(from, to, 1000);
  finish = clock();
  check(rc == 1000, "Normal copy failed: %d", rc);
  check(valid_copy(to, 1000, 'x'), "Normal copy failed.");
  printf("normal copy took %f seconds to execute.\n",
	 ((double) (finish - start)) / CLOCKS_PER_SEC );
  
  // reset
  memset(to, 'y', 1000);

  // duffs version
  start = clock();
  rc = duffs_device(from, to, 1000);
  finish = clock();
  check(rc == 1000, "Duff's device failed: %d", rc);
  check(valid_copy(to, 1000, 'x'), "Duff's device failed.");
  printf("duff copy took %f seconds to execute.\n",
	 ((double) (finish - start)) / CLOCKS_PER_SEC );

  // reset
  memset(to, 'y', 1000);

  // my version
  start = clock();
  rc = zeds_device(from, to, 1000);
  finish = clock();
  check(rc == 1000, "Zed's device failed: %d", rc);
  check(valid_copy(to, 1000, 'x'), "Zed's device failed.");
  printf("zeds copy took %f seconds to execute.\n",
	 ((double) (finish - start)) / CLOCKS_PER_SEC );

  return 0;

 error:
  return 1;
}
Example #7
0
int main(int argc, char *argv[])
{
    char from[1000] = {'a'};
    char to[1000] = {'c'};
    int rc = 0;
    double start;

    memset(from, 'x', 1000);
    memset(to, 'y', 1000);
    check(valid_copy(to, 1000, 'y'), "Not initialised right.");

    start = get_time();
    rc = normal_copy(from, to, 1000);
    log_info("normal_copy():%f", get_time() - start);

    check(rc == 1000, "Normal copy failed: %d", rc);
    check(valid_copy(to, 1000, 'x'), "Normal copy failed.");

    memset(to, 'y', 1000);

    start = get_time();
    memcpy(to, from, 1000);
    log_info("memcpy():%f", get_time() - start);

    check(valid_copy(to, 1000, 'x'), "memcpy failed.");

    memset(to, 'y', 1000);

    start = get_time();
    rc = duffs_device(from, to, 1000);
    log_info("duffs_device():%f", get_time() - start);

    check(rc == 1000, "Duff's device failed: %d", rc);
    check(valid_copy(to, 1000, 'x'), "Duff's device failed.");

    memset(to, 'y', 1000);

    start = get_time();
    rc = zeds_device(from, to, 1000);
    log_info("zeds_device():%f", get_time() - start);

    check(rc == 1000, "Zed's device failed: %d", rc);
    check(valid_copy(to, 1000, 'x'), "Zed's device failed.");

    return 0;

error:
    return 1;
}
Example #8
0
int main(int argc, char *argv[])
{
    char from[230000] = {'a'}; //allocates 230000 bytes with an initial of 'a' at index 0, note: have to make this big to see the difference in speed of those functions
    char to[230000] = {'c'};
    int rc = 0;
    
    // setup the from to have some stuff
    memset(from, 'x', 230000); //this seems fast, it sets all 230000 bytes to a character 'x'
    // set it to a failure mode
    memset(to, 'y', 230000);
    check(valid_copy(to, 230000, 'y'), "Not initialized right.");
    
    // use normal copy to
    rc = normal_copy(from, to, 230000);
    check(rc == 230000, "Normal copy failed: %d", rc);
    check(valid_copy(to, 230000, 'x'), "Normal copy failed.");
    
    // reset
    memset(to, 'y',230000);
    
    // duffs version
    rc = duffs_device(from, to, 230000);
    check(rc == 230000, "Duff's device failed: %d", rc);
    check(valid_copy(to, 230000, 'x'), "Duff's device failed copy.");
    
    // reset
    memset(to, 'y', 230000);
    
    // my version
    rc = zeds_device(from, to, 230000);
    check(rc == 230000, "Zed's device failed: %d", rc);
    check(valid_copy(to, 230000, 'x'), "Zed's device failed copy.");
    
    analytics(); //just prints to the console the speed data of each function
    
    return 0;
error:
    return 1;
}
Example #9
0
int main(int argc, char *argv[])
{
  char from[1000] = {'a'};
  char to[1000] = {'c'};
  int rc = 0;

  // setup the from to have some stuff
  memset(from, 'x', 1000);
  // set it to a failure mode
  memset(to, 'y', 1000);
  check(valid_copy(to, 1000, 'y'), "Not initialized right.");


  // use normal copy to
  rc = normal_copy(from, to, 1000);
  check(rc == 1000, "Normal copy failed: %d", rc);
  check(valid_copy(to, 1000, 'x'), "Normal copy fialed.");

  // reset
  memset(to, 'y', 1000);

  // duffs version
  rc = duffs_device(from, to, 1000);
  check(rc == 1000, "Duff's device failed: %d", rc);
  check(valid_copy(to, 1000, 'x'), "Duff's device failed copy.");
  log_info("%s\n\n%s", from, to);
  // reset
  memset(to, 'y', 1000);

  // my version
  rc = zeds_device(from, to, 1000);
  check(rc == 1000, "Zed's device failed: %d", rc);
  check(valid_copy(to, 1000, 'x'), "Zed's device failed copy.");

  return 0;
 error:
  return 1;
}