240 cout <<
sizeof(tr1::tuple<int, int, double>) << endl;
242 int * arrint =
new int[5];
243 double * arrdouble =
new double[10];
244 float * arrfloat =
new float[5];
246 __gnu_cxx::iota(arrfloat, arrfloat+5,1);
247 transform(arrfloat, arrfloat+5,arrfloat, bind1st(divides<float>(), 1));
248 for(
int i=0; i<5; ++i)
249 cout << arrfloat[i] <<
" ";
255 int *
A =
new int[5];
256 __gnu_cxx::iota(
A,
A+5, 1);
258 transform(
A,
A+5,
A, bind2nd(minus<int>(), 10));
259 for(
int i=0; i<5; ++i)
267 (*(BushJr.
vec))[0] = 100;
281 vector<int> v = *(BushJr.
vec);
282 cout << v.size() <<
" elements, occupying "<<
sizeof(v) <<
" bytes"<< endl;
294 T_promote result = a + b;
295 cout << result << endl;
297 vector<int>(3).swap(v);
298 cout <<
"size of v: " << v.size() <<
" , capacity of v: " << v.capacity() << endl;
300 cout <<
"******* vector performance test *******" << endl;
302 __gnu_cxx::iota(source, source+
TESTSIZE, 1);
304 vector<int> inserted;
307 gettimeofday(&tim, NULL);
308 double t1=tim.tv_sec+(tim.tv_usec/1000000.0);
310 std::copy(source, source+
TESTSIZE, destination.begin());
312 gettimeofday(&tim, NULL);
313 double t2=tim.tv_sec+(tim.tv_usec/1000000.0);
314 printf(
"%.6lf seconds elapsed for std::copy\n", t2-t1);
317 gettimeofday(&tim, NULL);
318 t1=tim.tv_sec+(tim.tv_usec/1000000.0);
320 inserted.insert(inserted.begin(), source, source+
TESTSIZE);
322 gettimeofday(&tim, NULL);
323 t2=tim.tv_sec+(tim.tv_usec/1000000.0);
324 printf(
"%.6lf seconds elapsed with insert\n", t2-t1);
327 gettimeofday(&tim, NULL);
328 t1=tim.tv_sec+(tim.tv_usec/1000000.0);
330 memcpy(&destination[0], source,
TESTSIZE*
sizeof(
int));
332 gettimeofday(&tim, NULL);
333 t2=tim.tv_sec+(tim.tv_usec/1000000.0);
334 printf(
"%.6lf seconds elapsed with memcpy\n", t2-t1);
337 gettimeofday(&tim, NULL);
338 t1=tim.tv_sec+(tim.tv_usec/1000000.0);
341 destination[i] = source[i];
343 gettimeofday(&tim, NULL);
344 t2=tim.tv_sec+(tim.tv_usec/1000000.0);
345 printf(
"%.6lf seconds elapsed with loops\n", t2-t1);
349 cout <<
"******* accumulate performance test *******" << endl;
351 gettimeofday(&tim, NULL);
352 t1=tim.tv_sec+(tim.tv_usec/1000000.0);
354 int acc =
fpaccumulate(destination.begin(), destination.end(), 0, plus<int>());
356 gettimeofday(&tim, NULL);
357 t2=tim.tv_sec+(tim.tv_usec/1000000.0);
358 printf(
"%.6lf seconds elapsed with plus<int> function object, gave result: %d\n", t2-t1, acc);
360 gettimeofday(&tim, NULL);
361 t1=tim.tv_sec+(tim.tv_usec/1000000.0);
364 acc = sraccumulate< PT > (destination.begin(), destination.end(), 0);
366 gettimeofday(&tim, NULL);
367 t2=tim.tv_sec+(tim.tv_usec/1000000.0);
368 printf(
"%.6lf seconds elapsed with SR::add static method, gave result: %d\n", t2-t1, acc);
371 gettimeofday(&tim, NULL);
372 t1=tim.tv_sec+(tim.tv_usec/1000000.0);
374 acc =
fpaccumulate(destination.begin(), destination.end(), 0, &add_func<int>);
376 gettimeofday(&tim, NULL);
377 t2=tim.tv_sec+(tim.tv_usec/1000000.0);
378 printf(
"%.6lf seconds elapsed with function pointer, gave result: %d\n", t2-t1, acc);
381 cout <<
"******* array of structs test *******" << endl;
385 __gnu_cxx::iota(linear, linear+
TESTSIZE, 0);
386 __gnu_cxx::iota(random, random+
TESTSIZE, 0);
387 random_shuffle(random, random+
TESTSIZE);
395 arrayofstrs[i].
first = 1;
396 arrayofstrs[i].
second = 2;
397 arrayofstrs[i].
third = 3;
399 strofarrays.
firsts[i] = 1;
401 strofarrays.
thirds[i] = 3;
404 gettimeofday(&tim, NULL);
405 t1=tim.tv_sec+(tim.tv_usec/1000000.0);
408 arrayofstrs[linear[i]].
first += 1;
409 arrayofstrs[linear[i]].
second += 2;
410 arrayofstrs[linear[i]].
third += 3;
412 gettimeofday(&tim, NULL);
413 t2=tim.tv_sec+(tim.tv_usec/1000000.0);
414 printf(
"%.6lf seconds elapsed for streaming array of structs\n", t2-t1);
416 gettimeofday(&tim, NULL);
417 t1=tim.tv_sec+(tim.tv_usec/1000000.0);
420 strofarrays.
firsts[linear[i]] += 1;
421 strofarrays.
seconds[linear[i]] += 2;
422 strofarrays.
thirds[linear[i]] += 3;
424 gettimeofday(&tim, NULL);
425 t2=tim.tv_sec+(tim.tv_usec/1000000.0);
426 printf(
"%.6lf seconds elapsed for streaming struct of arrays\n", t2-t1);
428 gettimeofday(&tim, NULL);
429 t1=tim.tv_sec+(tim.tv_usec/1000000.0);
432 arrayofstrs[random[i]].
first += 1;
433 arrayofstrs[random[i]].
second += 2;
434 arrayofstrs[random[i]].
third += 3;
436 gettimeofday(&tim, NULL);
437 t2=tim.tv_sec+(tim.tv_usec/1000000.0);
438 printf(
"%.6lf seconds elapsed for randomly accessing array of structs\n", t2-t1);
440 gettimeofday(&tim, NULL);
441 t1=tim.tv_sec+(tim.tv_usec/1000000.0);
444 strofarrays.
firsts[random[i]] += 1;
445 strofarrays.
seconds[random[i]] += 2;
446 strofarrays.
thirds[random[i]] += 3;
448 gettimeofday(&tim, NULL);
449 t2=tim.tv_sec+(tim.tv_usec/1000000.0);
450 printf(
"%.6lf seconds elapsed for randomly accessing struct of arrays\n", t2-t1);