1+
2+ #Import "<std>"
3+
4+ Using std..
5+
6+ Const ITEMS := 1000000
7+ Const MAXVALUE := 5000000
8+
9+ Enum Bench
10+ Base, Create, Union, Intersection, Difference
11+ End
12+
13+ Function Main()
14+
15+ Print "miniBench Map vs Set"
16+ Print "Items: "+ITEMS
17+
18+ Local timesMap := New Int[5]
19+ Local timesSet:= New Int[5]
20+ Local m1 := New Map<UInt,Bool>()
21+ Local s1 := New Set<UInt>( MAXVALUE, ITEMS )
22+ Local m2 := New Map<UInt,Bool>()
23+ Local s2 := New Set<UInt>( MAXVALUE, ITEMS )
24+
25+ SeedRnd(1234)
26+ timesMap[Bench.Base] = Millisecs()
27+ For Local i := 0 Until ITEMS
28+ m1.Add( UInt( Rnd( MAXVALUE ) ), True )
29+ m2.Add( UInt( Rnd( MAXVALUE ) ), True )
30+ Next
31+ timesMap[Bench.Create] = Millisecs()
32+ Local m_union := m1.Union( m2, False )
33+ timesMap[Bench.Union] = Millisecs()
34+ Local m_inter := m1.Intersect( m2, False )
35+ timesMap[Bench.Intersection] = Millisecs()
36+ Local m_diff := m1.Diff( m2, False )
37+ timesMap[Bench.Difference] = Millisecs()
38+
39+ SeedRnd(1234)
40+ timesSet[Bench.Base] = Millisecs()
41+ For Local i := 0 Until ITEMS
42+ s1.Add( UInt( Rnd( MAXVALUE ) ) )
43+ s2.Add( UInt( Rnd( MAXVALUE ) ) )
44+ Next
45+ timesSet[Bench.Create] = Millisecs()
46+ Local s_union := s1.Union( s2 )
47+ timesSet[Bench.Union] = Millisecs()
48+ Local s_inter := s1.Intersection( s2 )
49+ timesSet[Bench.Intersection] = Millisecs()
50+ Local s_diff := s1.Difference( s2 )
51+ timesSet[Bench.Difference] = Millisecs()
52+
53+ Local tmc := timesMap[Bench.Create] - timesMap[Bench.Base]
54+ Local tmu := timesMap[Bench.Union] - timesMap[Bench.Create]
55+ Local tmi := timesMap[Bench.Intersection] - timesMap[Bench.Union]
56+ Local tmd := timesMap[Bench.Difference] - timesMap[Bench.Intersection]
57+ Local tsc := timesSet[Bench.Create] - timesSet[Bench.Base]
58+ Local tsu := timesSet[Bench.Union] - timesSet[Bench.Create]
59+ Local tsi := timesSet[Bench.Intersection] - timesSet[Bench.Union]
60+ Local tsd := timesSet[Bench.Difference] - timesSet[Bench.Intersection]
61+
62+ Local amu := m_union.KeysToArray()
63+ Local asu := New Stack<UInt>( s_union.ToArray() )
64+ asu.Sort()
65+ Print "--------------------------"
66+ Print "Lenghts: " + amu.Length + " : " + asu.Length
67+ Print "Checking union..."
68+ For Local z := 0 Until amu.Length
69+ If amu[z] <> asu[z] Print "[" + z + "]: " + amu[z] + " - " + asu[z]
70+ Next
71+
72+ Local ami := m_inter.KeysToArray()
73+ Local asi := New Stack<UInt>( s_inter.ToArray() )
74+ asi.Sort()
75+ Print "--------------------------"
76+ Print "Lenghts: " + ami.Length + " : " + asi.Length
77+ Print "Checking intersection..."
78+ For Local z := 0 Until ami.Length
79+ If ami[z] <> asi[z] Print "[" + z + "]: " + ami[z] + " - " + asi[z]
80+ Next
81+
82+ Local amd := m_diff.KeysToArray()
83+ Local asd := New Stack<UInt>( s_diff.ToArray() )
84+ asd.Sort()
85+ Print "--------------------------"
86+ Print "Lenghts: " + amd.Length + " : " + asd.Length
87+ Print "Checking difference..."
88+ For Local z := 0 Until amd.Length
89+ If amd[z] <> asd[z] Print "[" + z + "]: " + amd[z] + " - " + asd[z]
90+ Next
91+
92+ Print "--------------------------"
93+ Print RSet("Create",20)+" "+RSet("Union",10)+" "+RSet("Intersection",15)+" "+RSet("Difference",15)
94+ Print LSet("Maps",10)+RSet(tmc,9)+" ms"+RSet(tmu,8)+" ms"+RSet(tmi,13)+" ms"+RSet(tmd,13)+" ms"
95+ Print LSet("Sets",10)+RSet(tsc,9)+" ms"+RSet(tsu,8)+" ms"+RSet(tsi,13)+" ms"+RSet(tsd,13)+" ms"
96+ Print LSet("%",10)+RSet(tmc*100/tsc,9)+"% "+RSet(tmu*100/tsu,9)+"% "+RSet(tmi*100/tsi,14)+"% "+RSet(tmd*100/tsd,14)+"%"
97+
98+ End
0 commit comments