Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 97 additions & 0 deletions examples/denise/set_vs_list_example.wx
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@

#Import "<std>"

Using std..

Const ITEMS := 1000000
Const MAXVALUE := 5000000

Enum Bench
Base, Create, Union, Intersection, Difference
End

Function Main()

Print "miniBench List vs Set"
Print "Items: "+ITEMS

Local timesList:= New Int[5]
Local timesSet:= New Int[5]
Local l1 := New List<UInt>()
Local s1 := New Set<UInt>( MAXVALUE, ITEMS )
Local l2 := New List<UInt>()
Local s2 := New Set<UInt>( MAXVALUE, ITEMS )

SeedRnd(1234)
timesList[Bench.Base] = Millisecs()
For Local i := 0 Until ITEMS
l1.Add( UInt( Rnd( MAXVALUE ) ) )
l2.Add( UInt( Rnd( MAXVALUE ) ) )
Next
timesList[Bench.Create] = Millisecs()
Local l_union := l1.Union( l2, False )
timesList[Bench.Union] = Millisecs()
Local l_inter := l1.Intersect( l2, False )
timesList[Bench.Intersection] = Millisecs()
Local l_diff := l1.Diff( l2, False )
timesList[Bench.Difference] = Millisecs()

SeedRnd(1234)
timesSet[Bench.Base] = Millisecs()
For Local i := 0 Until ITEMS
s1.Add( UInt( Rnd( MAXVALUE ) ) )
s2.Add( UInt( Rnd( MAXVALUE ) ) )
Next
timesSet[Bench.Create] = Millisecs()
Local s_union := s1.Union( s2 )
timesSet[Bench.Union] = Millisecs()
Local s_inter := s1.Intersection( s2 )
timesSet[Bench.Intersection] = Millisecs()
Local s_diff := s1.Difference( s2 )
timesSet[Bench.Difference] = Millisecs()

Local tlc := timesList[Bench.Create] - timesList[Bench.Base]
Local tlu := timesList[Bench.Union] - timesList[Bench.Create]
Local tli := timesList[Bench.Intersection] - timesList[Bench.Union]
Local tld := timesList[Bench.Difference] - timesList[Bench.Intersection]
Local tsc := timesSet[Bench.Create] - timesSet[Bench.Base]
Local tsu := timesSet[Bench.Union] - timesSet[Bench.Create]
Local tsi := timesSet[Bench.Intersection] - timesSet[Bench.Union]
Local tsd := timesSet[Bench.Difference] - timesSet[Bench.Intersection]

Local alu := l_union.ToArray()
Local asu := s_union.ToArray()
Print "--------------------------"
Print "Lenghts: " + alu.Length + " : " + asu.Length
Print "Checking union..."
For Local z := 0 Until alu.Length
If alu[z] <> asu[z] Print "[" + z + "]: " + alu[z] + " - " + asu[z]
Next

Local ali := l_inter.ToArray()
Local asi := New Stack<UInt>( s_inter.ToArray() )
asi.Sort()
Print "--------------------------"
Print "Lenghts: " + ali.Length + " : " + asi.Length
Print "Checking intersection..."
For Local z := 0 Until ali.Length
If ali[z] <> asi[z] Print "[" + z + "]: " + ali[z] + " - " + asi[z]
Next

Local ald := l_diff.ToArray()
Local asd := New Stack<UInt>( s_diff.ToArray() )
asd.Sort()
Print "--------------------------"
Print "Lenghts: " + ald.Length + " : " + asd.Length
Print "Checking difference..."
For Local z := 0 Until ald.Length
If ald[z] <> asd[z] Print "[" + z + "]: " + ald[z] + " - " + asd[z]
Next

Print "--------------------------"
Print RSet("Create",20)+" "+RSet("Union",10)+" "+RSet("Intersection",15)+" "+RSet("Difference",15)
Print LSet("Lists",10)+RSet(tlc,9)+" ms"+RSet(tlu,8)+" ms"+RSet(tli,13)+" ms"+RSet(tld,13)+" ms"
Print LSet("Sets",10)+RSet(tsc,9)+" ms"+RSet(tsu,8)+" ms"+RSet(tsi,13)+" ms"+RSet(tsd,13)+" ms"
Print LSet("%",10)+RSet(tlc*100/tsc,9)+"% "+RSet(tlu*100/tsu,9)+"% "+RSet(tli*100/tsi,14)+"% "+RSet(tld*100/tsd,14)+"%"

End
98 changes: 98 additions & 0 deletions examples/denise/set_vs_map_example.wx
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@

#Import "<std>"

Using std..

Const ITEMS := 1000000
Const MAXVALUE := 5000000

Enum Bench
Base, Create, Union, Intersection, Difference
End

Function Main()

Print "miniBench Map vs Set"
Print "Items: "+ITEMS

Local timesMap := New Int[5]
Local timesSet:= New Int[5]
Local m1 := New Map<UInt,Bool>()
Local s1 := New Set<UInt>( MAXVALUE, ITEMS )
Local m2 := New Map<UInt,Bool>()
Local s2 := New Set<UInt>( MAXVALUE, ITEMS )

SeedRnd(1234)
timesMap[Bench.Base] = Millisecs()
For Local i := 0 Until ITEMS
m1.Add( UInt( Rnd( MAXVALUE ) ), True )
m2.Add( UInt( Rnd( MAXVALUE ) ), True )
Next
timesMap[Bench.Create] = Millisecs()
Local m_union := m1.Union( m2, False )
timesMap[Bench.Union] = Millisecs()
Local m_inter := m1.Intersect( m2, False )
timesMap[Bench.Intersection] = Millisecs()
Local m_diff := m1.Diff( m2, False )
timesMap[Bench.Difference] = Millisecs()

SeedRnd(1234)
timesSet[Bench.Base] = Millisecs()
For Local i := 0 Until ITEMS
s1.Add( UInt( Rnd( MAXVALUE ) ) )
s2.Add( UInt( Rnd( MAXVALUE ) ) )
Next
timesSet[Bench.Create] = Millisecs()
Local s_union := s1.Union( s2 )
timesSet[Bench.Union] = Millisecs()
Local s_inter := s1.Intersection( s2 )
timesSet[Bench.Intersection] = Millisecs()
Local s_diff := s1.Difference( s2 )
timesSet[Bench.Difference] = Millisecs()

Local tmc := timesMap[Bench.Create] - timesMap[Bench.Base]
Local tmu := timesMap[Bench.Union] - timesMap[Bench.Create]
Local tmi := timesMap[Bench.Intersection] - timesMap[Bench.Union]
Local tmd := timesMap[Bench.Difference] - timesMap[Bench.Intersection]
Local tsc := timesSet[Bench.Create] - timesSet[Bench.Base]
Local tsu := timesSet[Bench.Union] - timesSet[Bench.Create]
Local tsi := timesSet[Bench.Intersection] - timesSet[Bench.Union]
Local tsd := timesSet[Bench.Difference] - timesSet[Bench.Intersection]

Local amu := m_union.KeysToArray()
Local asu := New Stack<UInt>( s_union.ToArray() )
asu.Sort()
Print "--------------------------"
Print "Lenghts: " + amu.Length + " : " + asu.Length
Print "Checking union..."
For Local z := 0 Until amu.Length
If amu[z] <> asu[z] Print "[" + z + "]: " + amu[z] + " - " + asu[z]
Next

Local ami := m_inter.KeysToArray()
Local asi := New Stack<UInt>( s_inter.ToArray() )
asi.Sort()
Print "--------------------------"
Print "Lenghts: " + ami.Length + " : " + asi.Length
Print "Checking intersection..."
For Local z := 0 Until ami.Length
If ami[z] <> asi[z] Print "[" + z + "]: " + ami[z] + " - " + asi[z]
Next

Local amd := m_diff.KeysToArray()
Local asd := New Stack<UInt>( s_diff.ToArray() )
asd.Sort()
Print "--------------------------"
Print "Lenghts: " + amd.Length + " : " + asd.Length
Print "Checking difference..."
For Local z := 0 Until amd.Length
If amd[z] <> asd[z] Print "[" + z + "]: " + amd[z] + " - " + asd[z]
Next

Print "--------------------------"
Print RSet("Create",20)+" "+RSet("Union",10)+" "+RSet("Intersection",15)+" "+RSet("Difference",15)
Print LSet("Maps",10)+RSet(tmc,9)+" ms"+RSet(tmu,8)+" ms"+RSet(tmi,13)+" ms"+RSet(tmd,13)+" ms"
Print LSet("Sets",10)+RSet(tsc,9)+" ms"+RSet(tsu,8)+" ms"+RSet(tsi,13)+" ms"+RSet(tsd,13)+" ms"
Print LSet("%",10)+RSet(tmc*100/tsc,9)+"% "+RSet(tmu*100/tsu,9)+"% "+RSet(tmi*100/tsi,14)+"% "+RSet(tmd*100/tsd,14)+"%"

End
80 changes: 80 additions & 0 deletions examples/denise/test_operator_to.wx
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@

#Import "<std>"

Using std..

Function Main()

Local ln := New List<Int>()
Local ls := New List<String>()
Local sn := New Stack<Int>()
Local ss := New Stack<String>()
Local dn := New Deque<Int>()
Local ds := New Deque<String>()
Local mnn := New Map<Int,Int>()
Local mns := New Map<Int,String>()
Local msn := New Map<String,Int>()
Local mss := New Map<String,String>()
Local sui := New Set<UInt>()

ln.Add( 1 )
ln.Add( 2 )
ln.Add( 3 )
Assert( ln = "List<Int>[ 1, 2, 3 ]", "Error: " + ln )

ls.Add( "1" )
ls.Add( "2" )
ls.Add( "3" )
Assert( ls = "List<String>[ 1, 2, 3 ]", "Error: " + ls )

sn.Add( 1 )
sn.Add( 2 )
sn.Add( 3 )
Assert( sn = "Stack<Int>[ 1, 2, 3 ]", "Error: " + sn )

ss.Add( "1" )
ss.Add( "2" )
ss.Add( "3" )
Assert( ss = "Stack<String>[ 1, 2, 3 ]", "Error: " + ss )

dn.AddFirst( 1 )
dn.AddFirst( 2 )
dn.AddLast( 3 )
dn.AddLast( 4 )
Assert( dn = "Deque<Int>[ 2, 1, 3, 4 ]", "Error: " + dn )

ds.AddFirst( "1" )
ds.AddFirst( "2" )
ds.AddLast( "3" )
ds.AddLast( "4" )
Assert( ds = "Deque<String>[ 2, 1, 3, 4 ]", "Error: " + ds )

mnn.Add( 1,2 )
mnn.Add( 3,4 )
mnn.Add( 1,5 )
Assert( mnn = "Map<Int,Int>{ 1: 2, 3: 4 }", "Error: " + mnn )

mns.Add( 1,"2" )
mns.Add( 3,"4" )
mns.Add( 1,"5" )
Assert( mns = "Map<Int,String>{ 1: 2, 3: 4 }", "Error: " + mns )

msn.Add( "1",2 )
msn.Add( "3",4 )
msn.Add( "1",5 )
Assert( msn = "Map<String,Int>{ 1: 2, 3: 4 }", "Error: " + msn )

mss.Add( "1","2" )
mss.Add( "3","4" )
mss.Add( "1","5" )
Assert( mss = "Map<String,String>{ 1: 2, 3: 4 }", "Error: " + mss )

sui.Add( 1 )
sui.Add( 2 )
sui.Add( 3 )
sui.Add( 2 )
Assert( sui = "Set<UInt>{ 1, 2, 3 }", "Error: " + sui )

Print "All Ok"

End
Loading
Loading