Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

Changeset 3707

Show
Ignore:
Timestamp:
07/04/08 23:37:30 (2 months ago)
Author:
kris
Message:

added a test case

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/tango/util/collection/HashSet.d

    r3463 r3707  
    576576        } 
    577577} 
     578 
     579 
     580 
     581debug (HashSet) 
     582{ 
     583        import tango.io.Stdout; 
     584        import tango.core.Thread; 
     585        import tango.time.StopWatch; 
     586         
     587        void main() 
     588        { 
     589                // setup for benchmark, with a set of integers. We 
     590                // use a chunk allocator, and presize the bucket[] 
     591                auto test = new HashSet!(int); 
     592                test.buckets = 700_000; 
     593                const count = 500_000; 
     594                StopWatch w; 
     595 
     596                // benchmark adding 
     597                w.start; 
     598                for (int i=count; i--;) 
     599                     test.add(i); 
     600                Stdout.formatln ("{} adds: {}/s", test.size, test.size/w.stop); 
     601 
     602                // benchmark reading 
     603                w.start; 
     604                for (int i=count; i--;) 
     605                     test.contains(i); 
     606                Stdout.formatln ("{} lookups: {}/s", test.size, test.size/w.stop); 
     607 
     608                // benchmark adding without allocation overhead 
     609                test.clear; 
     610                w.start; 
     611                for (int i=count; i--;) 
     612                     test.add(i); 
     613                Stdout.formatln ("{} adds (after clear): {}/s", test.size, test.size/w.stop); 
     614 
     615                // benchmark duplication 
     616                w.start; 
     617                auto dup = test.duplicate; 
     618                Stdout.formatln ("{} element dup: {}/s", dup.size, dup.size/w.stop); 
     619 
     620                // benchmark iteration 
     621                w.start; 
     622                foreach (value; test) {} 
     623                Stdout.formatln ("{} element iteration: {}/s", test.size, test.size/w.stop); 
     624                Thread.sleep (3); 
     625        } 
     626}