예제 #1
0
void
time_parallel_for ()
{
    std::cout << "\nTiming how long it takes to run parallel_for:\n";
    std::cout << "threads\ttime (best of " << ntrials << ")\n";
    std::cout << "-------\t----------\n";
    for (int i = 0; threadcounts[i] <= numthreads; ++i) {
        int nt = wedge ? threadcounts[i] : numthreads;
        int its = iterations/nt;

        // make a lambda function that spawns a bunch of threads, calls a
        // trivial function, then waits for them to finish and tears down
        // the group.
        auto func = [=](){
            parallel_for (0, nt, [](int64_t i){ /*empty*/ });
        };

        double range;
        double t = time_trial (func, ntrials, its, &range);

        std::cout << Strutil::format ("%2d\t%5.1f   launch %8.1f threads/sec\n",
                                      nt, t, (nt*its)/t);
        if (! wedge)
            break;    // don't loop if we're not wedging
    }
}
예제 #2
0
int
main(int argc, const char **argv)
{
	cpInitChipmunk();
	cp_collision_slop = 0.2f;
	
#ifdef TIME_TRIAL
	sleep(1);
	for(int i=0; i<demoCount; i++){
		if(i == 'l' - 'a') continue;
		time_trial(i, 1000);
	}
//	time_trial(0, 1000);
	exit(0);
#endif
	
	mouseBody = cpBodyNew(INFINITY, INFINITY);
	
	glutStuff(argc, argv);
	
	runDemo(demos[firstDemoIndex]);
	glutMainLoop();

	return 0;
}
예제 #3
0
int main (int argc, char *argv[])
{
#if !defined(NDEBUG) || defined(OIIO_CI) || defined(OIIO_CODECOV)
    // For the sake of test time, reduce the default iterations for DEBUG,
    // CI, and code coverage builds. Explicit use of --iters or --trials
    // will override this, since it comes before the getargs() call.
    iterations /= 10;
    ntrials = 1;
#endif

    getargs (argc, argv);

    std::cout << "hw threads = " << Sysutil::hardware_concurrency() << "\n";
    std::cout << "threads\ttime (best of " << ntrials << ")\n";
    std::cout << "-------\t----------\n";

    static int threadcounts[] = { 1, 2, 4, 8, 12, 16, 20, 24, 28, 32, 64, 128, 1024, 1<<30 };
    for (int i = 0; threadcounts[i] <= numthreads; ++i) {
        int nt = wedge ? threadcounts[i] : numthreads;
        int its = iterations/nt;

        double range;
        double t = time_trial (std::bind(test_atomics,nt,its),
                               ntrials, &range);

        std::cout << Strutil::format ("%2d\t%5.1f   range %.2f\t(%d iters/thread)\n",
                                      nt, t, range, its);
        if (! wedge)
            break;    // don't loop if we're not wedging
    }

    return unit_test_failures;
}
예제 #4
0
void
time_thread_group ()
{
    std::cout << "\nTiming how long it takes to start/end thread_group:\n";
    std::cout << "threads\ttime (best of " << ntrials << ")\n";
    std::cout << "-------\t----------\n";
    for (int i = 0; threadcounts[i] <= numthreads; ++i) {
        int nt = wedge ? threadcounts[i] : numthreads;
        int its = iterations/nt;

        // make a lambda function that spawns a bunch of threads, calls a
        // trivial function, then waits for them to finish and tears down
        // the group.
        auto func = [=](){
            thread_group g;
            for (int i = 0; i < nt; ++i)
                g.create_thread (do_nothing, i);
            g.join_all ();
        };

        double range;
        double t = time_trial (func, ntrials, its, &range);

        std::cout << Strutil::format ("%2d\t%5.1f   launch %8.1f threads/sec\n",
                                      nt, t, (nt*its)/t);
        if (! wedge)
            break;    // don't loop if we're not wedging
    }
}
예제 #5
0
void
time_thread_pool ()
{
    std::cout << "\nTiming how long it takes to launch from thread_pool:\n";
    std::cout << "threads\ttime (best of " << ntrials << ")\n";
    std::cout << "-------\t----------\n";
    thread_pool *pool (default_thread_pool());
    for (int i = 0; threadcounts[i] <= numthreads; ++i) {
        int nt = wedge ? threadcounts[i] : numthreads;
        pool->resize (nt);
        int its = iterations/nt;

        // make a lambda function that spawns a bunch of threads, calls a
        // trivial function, then waits for them to finish and tears down
        // the group.
        auto func = [=](){
            task_set<void> taskset (pool);
            for (int i = 0; i < nt; ++i) {
                taskset.push (pool->push (do_nothing));
            }
            taskset.wait();
        };

        double range;
        double t = time_trial (func, ntrials, its, &range);

        std::cout << Strutil::format ("%2d\t%5.1f   launch %8.1f threads/sec\n",
                                      nt, t, (nt*its)/t);
        if (! wedge)
            break;    // don't loop if we're not wedging
    }
}
예제 #6
0
int
main(int argc, const char **argv)
{
	ChipmunkDemo demo_list[] = {
		LogoSmash,
		PyramidStack,
		Plink,
		BouncyHexagons,
		Tumble,
		PyramidTopple,
		Planet,
		Springies,
		Pump,
		TheoJansen,
		Query,
		OneWay,
		Joints,
		Tank,
		Chains,
		Crane,
		ContactGraph,
		Buoyancy,
		Player,
		Slice,
		Convex,
		Unicycle,
	};
	
	demos = demo_list;
	demoCount = sizeof(demo_list)/sizeof(ChipmunkDemo);
	int trial = 0;
	
	for(int i=0; i<argc; i++){
		if(strcmp(argv[i], "-bench") == 0){
			demos = bench_list;
			demoCount = bench_count;
		} else if(strcmp(argv[i], "-trial") == 0){
			trial = 1;
		}
	}
	
	if(trial){
//		sleep(1);
		for(int i=0; i<demoCount; i++) time_trial(i, 1000);
//		time_trial('d' - 'a', 10000);
		exit(0);
	} else {
		mouseBody = cpBodyNew(INFINITY, INFINITY);
		
		glutStuff(argc, argv);
		
		runDemo(demoIndex);
		glutMainLoop();
	}

	return 0;
}
예제 #7
0
int
main (int argc, char **argv)
{
    getargs (argc, argv);

    if (input_filename.empty()) {
        std::cout << "Error: Must supply a filename.\n";
        return -1;
    }

    imagecache = ImageCache::create ();
    imagecache->attribute ("forcefloat", 1);

    // Allocate a buffer big enough (for floats)
    bool ok = imagecache->get_imagespec (input_filename, spec);
    ASSERT (ok);
    imagecache->invalidate_all (true);  // Don't hold anything
    buffer.resize (spec.image_pixels()*spec.nchannels*sizeof(float), 0);

    {
        double t = time_trial (time_read_image, ntrials);
        std::cout << "image_read speed: " << Strutil::timeintervalformat(t,2) << "\n";
    }

    {
        double t = time_trial (time_read_imagebuf, ntrials);
        std::cout << "ImageBuf read speed: " << Strutil::timeintervalformat(t,2) << "\n";
    }

    {
        double t = time_trial (time_ic_get_pixels, ntrials);
        std::cout << "ImageCache get_pixels speed: " << Strutil::timeintervalformat(t,2) << "\n";
    }

    imagecache->invalidate_all (true);  // Don't hold anything

    ImageCache::destroy (imagecache);
    return unit_test_failures;
}
예제 #8
0
파일: fmath_test.cpp 프로젝트: ElaraFX/oiio
void benchmark_convert_type ()
{
    const size_t size = 10000000;
    const S testval(1.0);
    std::vector<S> svec (size, testval);
    std::vector<D> dvec (size);
    std::cout << Strutil::format("Benchmark conversion of %6s -> %6s : ",
                                 TypeDesc(BaseTypeFromC<S>::value),
                                 TypeDesc(BaseTypeFromC<D>::value));
    float time = time_trial (bind (do_convert_type<S,D>, OIIO::cref(svec), OIIO::ref(dvec)),
                             ntrials, iterations) / iterations;
    std::cout << Strutil::format ("%7.1f Mvals/sec", (size/1.0e6)/time) << std::endl;
    D r = convert_type<S,D>(testval);
    OIIO_CHECK_EQUAL (dvec[size-1], r);
}
예제 #9
0
파일: hash_test.cpp 프로젝트: ElaraFX/oiio
int main (int argc, char *argv[])
{
#if !defined(NDEBUG) || defined(OIIO_CI) || defined(OIIO_CODECOV)
    // For the sake of test time, reduce the default iterations for DEBUG,
    // CI, and code coverage builds. Explicit use of --iters or --trials
    // will override this, since it comes before the getargs() call.
    iterations /= 10;
    ntrials = 1;
#endif

    getargs (argc, argv);

    double t;

    std::cout << "All times are seconds per " << iterations << " bytes.\n\n";

    t = time_trial (test_bjhash_small, ntrials);
    std::cout << "BJ hash of small data as bytes: " 
              << Strutil::timeintervalformat(t, 2) << "\n";
    t = time_trial (test_bjhash_small_words, ntrials);
    std::cout << "BJ hash of small data as words: " 
              << Strutil::timeintervalformat(t, 2) << "\n";
    t = time_trial (test_bjhash_big, ntrials);
    std::cout << "BJ hash of big data: " 
              << Strutil::timeintervalformat(t, 2) << "\n";
    t = time_trial (test_bjhash_big_words, ntrials);
    std::cout << "BJ hash of big data as words: " 
              << Strutil::timeintervalformat(t, 2) << "\n";

    t = time_trial (boost::bind(test_xxhash, &data[0], 2*sizeof(data[0])), ntrials);
    std::cout << "XX hash of small data: " 
              << Strutil::timeintervalformat(t, 2) << "\n";
    t = time_trial (boost::bind(test_xxhash, &data[0], data.size()*sizeof(data[0])), ntrials);
    std::cout << "XX hash of big data: " 
              << Strutil::timeintervalformat(t, 2) << "\n";

    t = time_trial (boost::bind(test_bjstrhash, shortstring), ntrials);
    std::cout << "BJ strhash hash of short string: "
              << Strutil::timeintervalformat(t, 2) << "\n";
    t = time_trial (boost::bind(test_bjstrhash, medstring), ntrials);
    std::cout << "BJ strhash hash of medium string: "
              << Strutil::timeintervalformat(t, 2) << "\n";
    t = time_trial (boost::bind(test_bjstrhash, longstring), ntrials);
    std::cout << "BJ strhash hash of long string: "
              << Strutil::timeintervalformat(t, 2) << "\n";

    t = time_trial (boost::bind(test_farmhashstr, shortstring), ntrials);
    std::cout << "farmhash of short string: "
              << Strutil::timeintervalformat(t, 2) << "\n";
    t = time_trial (boost::bind(test_farmhashstr, medstring), ntrials);
    std::cout << "farmhash of medium string: "
              << Strutil::timeintervalformat(t, 2) << "\n";
    t = time_trial (boost::bind(test_farmhashstr, longstring), ntrials);
    std::cout << "farmhash of long string: "
              << Strutil::timeintervalformat(t, 2) << "\n";

    t = time_trial (boost::bind(test_farmhashchar, shortstring.c_str()), ntrials);
    std::cout << "farmhash of short char*: "
              << Strutil::timeintervalformat(t, 2) << "\n";
    t = time_trial (boost::bind(test_farmhashchar, medstring.c_str()), ntrials);
    std::cout << "farmhash of medium char*: "
              << Strutil::timeintervalformat(t, 2) << "\n";
    t = time_trial (boost::bind(test_farmhashchar, longstring.c_str()), ntrials);
    std::cout << "farmhash of long char*: "
              << Strutil::timeintervalformat(t, 2) << "\n";

    t = time_trial (boost::bind(test_xxhash, shortstring.c_str(), shortstring.length()), ntrials);
    std::cout << "xxhash XH64 of short string: "
              << Strutil::timeintervalformat(t, 2) << "\n";
    t = time_trial (boost::bind(test_xxhash, medstring.c_str(), medstring.length()), ntrials);
    std::cout << "xxhash XH64 of medium string: "
              << Strutil::timeintervalformat(t, 2) << "\n";
    t = time_trial (boost::bind(test_xxhash, longstring.c_str(), longstring.length()), ntrials);
    std::cout << "xxhash XH64 of long string: "
              << Strutil::timeintervalformat(t, 2) << "\n";

    return unit_test_failures;
}
예제 #10
0
void
test_compute ()
{
    double time;

    ROI roi (0, xres, 0, yres, 0, 1, 0, channels);

    std::cout << "Test straightforward as 1D array of float: ";
    ImageBufAlgo::zero (imgR);
    time = time_trial (OIIO::bind (test_arrays, roi), ntrials, iterations) / iterations;
    std::cout << Strutil::format ("%.1f Mvals/sec", (size/1.0e6)/time) << std::endl;
    OIIO_CHECK_EQUAL_THRESH (imgR.getchannel(xres/2,yres/2,0,0), 0.25, 0.001);
    OIIO_CHECK_EQUAL_THRESH (imgR.getchannel(xres/2,yres/2,0,1), 0.25, 0.001);
    OIIO_CHECK_EQUAL_THRESH (imgR.getchannel(xres/2,yres/2,0,2), 0.50, 0.001);
    // imgR.write ("ref.exr");

    std::cout << "Test array iterated like an image: ";
    ImageBufAlgo::zero (imgR);
    time = time_trial (OIIO::bind (test_arrays_like_image, roi), ntrials, iterations) / iterations;
    std::cout << Strutil::format ("%.1f Mvals/sec", (size/1.0e6)/time) << std::endl;
    OIIO_CHECK_EQUAL_THRESH (imgR.getchannel(xres/2,yres/2,0,0), 0.25, 0.001);
    OIIO_CHECK_EQUAL_THRESH (imgR.getchannel(xres/2,yres/2,0,1), 0.25, 0.001);
    OIIO_CHECK_EQUAL_THRESH (imgR.getchannel(xres/2,yres/2,0,2), 0.50, 0.001);

    std::cout << "Test array iterated like an image, multithreaded: ";
    ImageBufAlgo::zero (imgR);
    time = time_trial (OIIO::bind (test_arrays_like_image_multithread_wrapper, roi), ntrials, iterations) / iterations;
    std::cout << Strutil::format ("%.1f Mvals/sec", (size/1.0e6)/time) << std::endl;
    OIIO_CHECK_EQUAL_THRESH (imgR.getchannel(xres/2,yres/2,0,0), 0.25, 0.001);
    OIIO_CHECK_EQUAL_THRESH (imgR.getchannel(xres/2,yres/2,0,1), 0.25, 0.001);
    OIIO_CHECK_EQUAL_THRESH (imgR.getchannel(xres/2,yres/2,0,2), 0.50, 0.001);

    std::cout << "Test array as 1D, using SIMD: ";
    ImageBufAlgo::zero (imgR);
    time = time_trial (OIIO::bind (test_arrays_simd4, roi), ntrials, iterations) / iterations;
    std::cout << Strutil::format ("%.1f Mvals/sec", (size/1.0e6)/time) << std::endl;
    OIIO_CHECK_EQUAL_THRESH (imgR.getchannel(xres/2,yres/2,0,0), 0.25, 0.001);
    OIIO_CHECK_EQUAL_THRESH (imgR.getchannel(xres/2,yres/2,0,1), 0.25, 0.001);
    OIIO_CHECK_EQUAL_THRESH (imgR.getchannel(xres/2,yres/2,0,2), 0.50, 0.001);

    std::cout << "Test array iterated like an image, using SIMD: ";
    ImageBufAlgo::zero (imgR);
    time = time_trial (OIIO::bind (test_arrays_like_image_simd, roi), ntrials, iterations) / iterations;
    std::cout << Strutil::format ("%.1f Mvals/sec", (size/1.0e6)/time) << std::endl;
    OIIO_CHECK_EQUAL_THRESH (imgR.getchannel(xres/2,yres/2,0,0), 0.25, 0.001);
    OIIO_CHECK_EQUAL_THRESH (imgR.getchannel(xres/2,yres/2,0,1), 0.25, 0.001);
    OIIO_CHECK_EQUAL_THRESH (imgR.getchannel(xres/2,yres/2,0,2), 0.50, 0.001);

    std::cout << "Test array iterated like an image, using SIMD, multithreaded: ";
    ImageBufAlgo::zero (imgR);
    time = time_trial (OIIO::bind (test_arrays_like_image_simd_multithread_wrapper, roi), ntrials, iterations) / iterations;
    std::cout << Strutil::format ("%.1f Mvals/sec", (size/1.0e6)/time) << std::endl;
    OIIO_CHECK_EQUAL_THRESH (imgR.getchannel(xres/2,yres/2,0,0), 0.25, 0.001);
    OIIO_CHECK_EQUAL_THRESH (imgR.getchannel(xres/2,yres/2,0,1), 0.25, 0.001);
    OIIO_CHECK_EQUAL_THRESH (imgR.getchannel(xres/2,yres/2,0,2), 0.50, 0.001);

    std::cout << "Test ImageBufAlgo::mad 1 thread: ";
    ImageBufAlgo::zero (imgR);
    time = time_trial (OIIO::bind (test_IBA, roi, 1),
                       ntrials, iterations) / iterations;
    std::cout << Strutil::format ("%.1f Mvals/sec", (size/1.0e6)/time) << std::endl;
    OIIO_CHECK_EQUAL_THRESH (imgR.getchannel(xres/2,yres/2,0,0), 0.25, 0.001);
    OIIO_CHECK_EQUAL_THRESH (imgR.getchannel(xres/2,yres/2,0,1), 0.25, 0.001);
    OIIO_CHECK_EQUAL_THRESH (imgR.getchannel(xres/2,yres/2,0,2), 0.50, 0.001);

    std::cout << "Test ImageBufAlgo::mad multi-thread " << numthreads << ": ";
    ImageBufAlgo::zero (imgR);
    time = time_trial (OIIO::bind (test_IBA, roi, numthreads),
                       ntrials, iterations) / iterations;
    std::cout << Strutil::format ("%.1f Mvals/sec", (size/1.0e6)/time) << std::endl;
    OIIO_CHECK_EQUAL_THRESH (imgR.getchannel(xres/2,yres/2,0,0), 0.25, 0.001);
    OIIO_CHECK_EQUAL_THRESH (imgR.getchannel(xres/2,yres/2,0,1), 0.25, 0.001);
    OIIO_CHECK_EQUAL_THRESH (imgR.getchannel(xres/2,yres/2,0,2), 0.50, 0.001);
}
예제 #11
0
int main(void)
{
    test_suite();
    time_trial();
    return 0;
}
예제 #12
0
int
main (int argc, char **argv)
{
    getargs (argc, argv);

    if (input_filename.empty()) {
        std::cout << "Error: Must supply a filename.\n";
        return -1;
    }

    imagecache = ImageCache::create ();
    imagecache->attribute ("forcefloat", 1);

    // Allocate a buffer big enough (for floats)
    bool ok = imagecache->get_imagespec (input_filename, spec, 0, 0, true);
    ASSERT (ok);
    imagecache->invalidate_all (true);  // Don't hold anything
    buffer.resize (spec.image_pixels()*spec.nchannels*sizeof(float), 0);
 
    {
        double t = time_trial (time_read_image, ntrials);
        std::cout << "read_image speed: " << Strutil::timeintervalformat(t,2) << "\n";
    }

    if (spec.tile_width == 0) {
        double t = time_trial (time_read_scanline_at_a_time, ntrials);
        std::cout << "read_scanline (1 at a time) speed: " << Strutil::timeintervalformat(t,2) << "\n";
    }

    if (spec.tile_width == 0) {
        double t = time_trial (time_read_64_scanlines_at_a_time, ntrials);
        std::cout << "read_scanlines (64 at a time) speed: " << Strutil::timeintervalformat(t,2) << "\n";
    }
    {
        imagecache->invalidate_all (true);  // Don't hold anything
        double t = time_trial (time_read_imagebuf, ntrials);
        std::cout << "ImageBuf read speed: " << Strutil::timeintervalformat(t,2) << "\n";
    }

    {
        imagecache->invalidate_all (true);  // Don't hold anything
        double t = time_trial (time_ic_get_pixels, ntrials);
        std::cout << "ImageCache get_pixels speed: " << Strutil::timeintervalformat(t,2) << "\n";
    }

    std::cout << "With autotile = 64:\n";
    imagecache->attribute ("autotile", 64);
    {
        imagecache->invalidate_all (true);  // Don't hold anything
        double t = time_trial (time_read_imagebuf, ntrials);
        std::cout << "ImageBuf read speed: " << Strutil::timeintervalformat(t,2) << "\n";
    }
    {
        imagecache->invalidate_all (true);  // Don't hold anything
        double t = time_trial (time_ic_get_pixels, ntrials);
        std::cout << "ImageCache get_pixels speed: " << Strutil::timeintervalformat(t,2) << "\n";
    }

    std::cout << "With autotile = 64, autoscanline = 1:\n";
    imagecache->attribute ("autotile", 64);
    imagecache->attribute ("autoscanline", 1);
    {
        imagecache->invalidate_all (true);  // Don't hold anything
        double t = time_trial (time_read_imagebuf, ntrials);
        std::cout << "ImageBuf read speed: " << Strutil::timeintervalformat(t,2) << "\n";
    }
    {
        imagecache->invalidate_all (true);  // Don't hold anything
        double t = time_trial (time_ic_get_pixels, ntrials);
        std::cout << "ImageCache get_pixels speed: " << Strutil::timeintervalformat(t,2) << "\n";
    }

    if (verbose)
        std::cout << "\n" << imagecache->getstats(2) << "\n";

    imagecache->invalidate_all (true);  // Don't hold anything

    ImageCache::destroy (imagecache);
    return unit_test_failures;
}