Skip to content

Commit e8b6d7c

Browse files
authored
Merge pull request #101 from denise-amiga/develop
Minor modules updated (Collections).
2 parents 0d49aa0 + b907c4c commit e8b6d7c

9 files changed

Lines changed: 1410 additions & 962 deletions

File tree

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
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 List vs Set"
16+
Print "Items: "+ITEMS
17+
18+
Local timesList:= New Int[5]
19+
Local timesSet:= New Int[5]
20+
Local l1 := New List<UInt>()
21+
Local s1 := New Set<UInt>( MAXVALUE, ITEMS )
22+
Local l2 := New List<UInt>()
23+
Local s2 := New Set<UInt>( MAXVALUE, ITEMS )
24+
25+
SeedRnd(1234)
26+
timesList[Bench.Base] = Millisecs()
27+
For Local i := 0 Until ITEMS
28+
l1.Add( UInt( Rnd( MAXVALUE ) ) )
29+
l2.Add( UInt( Rnd( MAXVALUE ) ) )
30+
Next
31+
timesList[Bench.Create] = Millisecs()
32+
Local l_union := l1.Union( l2, False )
33+
timesList[Bench.Union] = Millisecs()
34+
Local l_inter := l1.Intersect( l2, False )
35+
timesList[Bench.Intersection] = Millisecs()
36+
Local l_diff := l1.Diff( l2, False )
37+
timesList[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 tlc := timesList[Bench.Create] - timesList[Bench.Base]
54+
Local tlu := timesList[Bench.Union] - timesList[Bench.Create]
55+
Local tli := timesList[Bench.Intersection] - timesList[Bench.Union]
56+
Local tld := timesList[Bench.Difference] - timesList[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 alu := l_union.ToArray()
63+
Local asu := s_union.ToArray()
64+
Print "--------------------------"
65+
Print "Lenghts: " + alu.Length + " : " + asu.Length
66+
Print "Checking union..."
67+
For Local z := 0 Until alu.Length
68+
If alu[z] <> asu[z] Print "[" + z + "]: " + alu[z] + " - " + asu[z]
69+
Next
70+
71+
Local ali := l_inter.ToArray()
72+
Local asi := New Stack<UInt>( s_inter.ToArray() )
73+
asi.Sort()
74+
Print "--------------------------"
75+
Print "Lenghts: " + ali.Length + " : " + asi.Length
76+
Print "Checking intersection..."
77+
For Local z := 0 Until ali.Length
78+
If ali[z] <> asi[z] Print "[" + z + "]: " + ali[z] + " - " + asi[z]
79+
Next
80+
81+
Local ald := l_diff.ToArray()
82+
Local asd := New Stack<UInt>( s_diff.ToArray() )
83+
asd.Sort()
84+
Print "--------------------------"
85+
Print "Lenghts: " + ald.Length + " : " + asd.Length
86+
Print "Checking difference..."
87+
For Local z := 0 Until ald.Length
88+
If ald[z] <> asd[z] Print "[" + z + "]: " + ald[z] + " - " + asd[z]
89+
Next
90+
91+
Print "--------------------------"
92+
Print RSet("Create",20)+" "+RSet("Union",10)+" "+RSet("Intersection",15)+" "+RSet("Difference",15)
93+
Print LSet("Lists",10)+RSet(tlc,9)+" ms"+RSet(tlu,8)+" ms"+RSet(tli,13)+" ms"+RSet(tld,13)+" ms"
94+
Print LSet("Sets",10)+RSet(tsc,9)+" ms"+RSet(tsu,8)+" ms"+RSet(tsi,13)+" ms"+RSet(tsd,13)+" ms"
95+
Print LSet("%",10)+RSet(tlc*100/tsc,9)+"% "+RSet(tlu*100/tsu,9)+"% "+RSet(tli*100/tsi,14)+"% "+RSet(tld*100/tsd,14)+"%"
96+
97+
End
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
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
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
2+
#Import "<std>"
3+
4+
Using std..
5+
6+
Function Main()
7+
8+
Local ln := New List<Int>()
9+
Local ls := New List<String>()
10+
Local sn := New Stack<Int>()
11+
Local ss := New Stack<String>()
12+
Local dn := New Deque<Int>()
13+
Local ds := New Deque<String>()
14+
Local mnn := New Map<Int,Int>()
15+
Local mns := New Map<Int,String>()
16+
Local msn := New Map<String,Int>()
17+
Local mss := New Map<String,String>()
18+
Local sui := New Set<UInt>()
19+
20+
ln.Add( 1 )
21+
ln.Add( 2 )
22+
ln.Add( 3 )
23+
Assert( ln = "List<Int>[ 1, 2, 3 ]", "Error: " + ln )
24+
25+
ls.Add( "1" )
26+
ls.Add( "2" )
27+
ls.Add( "3" )
28+
Assert( ls = "List<String>[ 1, 2, 3 ]", "Error: " + ls )
29+
30+
sn.Add( 1 )
31+
sn.Add( 2 )
32+
sn.Add( 3 )
33+
Assert( sn = "Stack<Int>[ 1, 2, 3 ]", "Error: " + sn )
34+
35+
ss.Add( "1" )
36+
ss.Add( "2" )
37+
ss.Add( "3" )
38+
Assert( ss = "Stack<String>[ 1, 2, 3 ]", "Error: " + ss )
39+
40+
dn.AddFirst( 1 )
41+
dn.AddFirst( 2 )
42+
dn.AddLast( 3 )
43+
dn.AddLast( 4 )
44+
Assert( dn = "Deque<Int>[ 2, 1, 3, 4 ]", "Error: " + dn )
45+
46+
ds.AddFirst( "1" )
47+
ds.AddFirst( "2" )
48+
ds.AddLast( "3" )
49+
ds.AddLast( "4" )
50+
Assert( ds = "Deque<String>[ 2, 1, 3, 4 ]", "Error: " + ds )
51+
52+
mnn.Add( 1,2 )
53+
mnn.Add( 3,4 )
54+
mnn.Add( 1,5 )
55+
Assert( mnn = "Map<Int,Int>{ 1: 2, 3: 4 }", "Error: " + mnn )
56+
57+
mns.Add( 1,"2" )
58+
mns.Add( 3,"4" )
59+
mns.Add( 1,"5" )
60+
Assert( mns = "Map<Int,String>{ 1: 2, 3: 4 }", "Error: " + mns )
61+
62+
msn.Add( "1",2 )
63+
msn.Add( "3",4 )
64+
msn.Add( "1",5 )
65+
Assert( msn = "Map<String,Int>{ 1: 2, 3: 4 }", "Error: " + msn )
66+
67+
mss.Add( "1","2" )
68+
mss.Add( "3","4" )
69+
mss.Add( "1","5" )
70+
Assert( mss = "Map<String,String>{ 1: 2, 3: 4 }", "Error: " + mss )
71+
72+
sui.Add( 1 )
73+
sui.Add( 2 )
74+
sui.Add( 3 )
75+
sui.Add( 2 )
76+
Assert( sui = "Set<UInt>{ 1, 2, 3 }", "Error: " + sui )
77+
78+
Print "All Ok"
79+
80+
End

0 commit comments

Comments
 (0)