Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Strict
- #ANDROID_APP_LABEL="DataTypes Test"
- #HTML5_TRANSPILE_KILL_SWITCH_ENABLED=True
- Import examplebaseapp
- #IF CERBERUSX
- Import cerberus.stack
- #Else
- Import monkey.stack
- #Endif
- #IF TARGET = "html5"
- Const TARGET_NAME := "HTML5"
- #Elseif TARGET = "ios"
- Const TARGET_NAME := "iOS"
- #ElseIf TARGET = "android"
- Const TARGET_NAME := "Android"
- #Else
- Const TARGET_NAME := "Unknown Target"
- #Endif
- Const CHUNK_SIZE := 128
- Const INT_ITERATIONS := 1000000
- Const FLOAT_ITERATIONS := INT_ITERATIONS
- Const STRING_ITERATIONS := 1000
- Const INT_ARRAY_ITERATIONS := 10000
- Const FLOAT_ARRAY_ITERATIONS := INT_ARRAY_ITERATIONS
- Const STRING_ARRAY_ITERATIONS := INT_ARRAY_ITERATIONS
- Const TESTS_MIN := 0
- Const TESTS_MAX := 8
- Const TEST_ALL := -1
- Const TEST_INTS := 0
- Const TEST_FLOATS := 1
- Const TEST_STRINGS := 2
- Const TEST_INT_ARRAYS := 3
- Const TEST_FLOAT_ARRAYS := 4
- Const TEST_STRING_ARRAYS := 5
- Const TEST_CHUNKED_INT_ARRAYS := 6
- Const TEST_CHUNKED_FLOAT_ARRAYS := 7
- Const TEST_CHUNKED_STRING_ARRAYS := 8
- Global TEST_LABELS := ["ints", "floats", "strings", "int arrays", "float arrays", "string arrays", "chunked int arrays", "chunked float arrays", "chunked string arrays"]
- Function Main:Int()
- New MyApp()
- Return 0
- End
- Class MyApp Extends ExampleBaseApp
- Field sessionActive := False
- Field sessionCount:Int
- Field sessionWhich:Int
- Field sessionResults:StringStack
- Field sessionIterations:Int
- Field currentTest:Int
- Field currentTestStarted := False
- Field currentTestIteration:int
- Field currentTestCount:Int
- Method OnExampleCreate:Void()
- AddButton("runTestAllX1", "Test All x1", "33%")
- AddButton("runTestAllX25", "Test All x25", "33%")
- AddButton("runTestAllX100", "Test All x100", "fill")
- AddButton("runTestIntsX1", "Test Ints x1", "33%")
- AddButton("runTestIntsX25", "Test Ints x25", "33%")
- AddButton("runTestIntsX100", "Test Ints x100", "fill")
- AddButton("runTestFloatsX1", "Test Floats x1", "33%")
- AddButton("runTestFloatsX25", "Test Floats x25", "33%")
- AddButton("runTestFloatsX100", "Test Floats x100", "fill")
- AddButton("runTestStringsX1", "Test Strings x1", "33%")
- AddButton("runTestStringsX25", "Test Strings x25", "33%")
- AddButton("runTestStringsX100", "Test Strings x100", "fill")
- AddButton("runTestIntArraysX1", "Test Int Arrays x1", "33%")
- AddButton("runTestIntArraysX25", "Test Int Arrays x25", "33%")
- AddButton("runTestIntArraysX100", "Test Int Arrays x100", "fill")
- AddButton("runTestFloatArraysX1", "Test Float Arrays x1", "33%")
- AddButton("runTestFloatArraysX25", "Test Float Arrays x25", "33%")
- AddButton("runTestFloatArraysX100", "Test Float Arrays x100", "fill")
- AddButton("runTestStringArraysX1", "Test String Arrays x1", "33%")
- AddButton("runTestStringArraysX25", "Test String Arrays x25", "33%")
- AddButton("runTestStringArraysX100", "Test String Arrays x100", "fill")
- AddButton("runTestChunkedIntArraysX1", "Test Chunked Int Arrays x1", "33%")
- AddButton("runTestChunkedIntArraysX25", "Test Chunked Int Arrays x25", "33%")
- AddButton("runTestChunkedIntArraysX100", "Test Chunked Int Arrays x100", "fill")
- AddButton("runTestChunkedFloatArraysX1", "Test Chunked Float Arrays x1", "33%")
- AddButton("runTestChunkedFloatArraysX25", "Test Chunked Float Arrays x25", "33%")
- AddButton("runTestChunkedFloatArraysX100", "Test FChunked loat Arrays x100", "fill")
- AddButton("runTestChunkedStringArraysX1", "Test Chunked String Arrays x1", "33%")
- AddButton("runTestChunkedStringArraysX25", "Test Chunked String Arrays x25", "33%")
- AddButton("runTestChunkedStringArraysX100", "Test Chunked String Arrays x100", "fill")
- End
- Method OnExampleUpdate:Void()
- If sessionActive
- UpdateTests()
- Endif
- End
- Method OnButtonPressed:Void(id:String, button:Button)
- Select id
- Case "runTestAllX1"
- StartTests(TEST_ALL, 1)
- Case "runTestAllX25"
- StartTests(TEST_ALL, 25)
- Case "runTestAllX100"
- StartTests(TEST_ALL, 100)
- Case "runTestIntsX1"
- StartTests(TEST_INTS, 1)
- Case "runTestIntsX25"
- StartTests(TEST_INTS, 25)
- Case "runTestIntsX100"
- StartTests(TEST_INTS, 100)
- Case "runTestFloatsX1"
- StartTests(TEST_FLOATS, 1)
- Case "runTestFloatsX25"
- StartTests(TEST_FLOATS, 25)
- Case "runTestFloatsX100"
- StartTests(TEST_FLOATS, 100)
- Case "runTestStringsX1"
- StartTests(TEST_STRINGS, 1)
- Case "runTestStringsX25"
- StartTests(TEST_STRINGS, 25)
- Case "runTestStringsX100"
- StartTests(TEST_STRINGS, 100)
- Case "runTestIntArraysX1"
- StartTests(TEST_INT_ARRAYS, 1)
- Case "runTestIntArraysX25"
- StartTests(TEST_INT_ARRAYS, 25)
- Case "runTestIntArraysX100"
- StartTests(TEST_INT_ARRAYS, 100)
- Case "runTestFloatArraysX1"
- StartTests(TEST_FLOAT_ARRAYS, 1)
- Case "runTestFloatArraysX25"
- StartTests(TEST_FLOAT_ARRAYS, 25)
- Case "runTestFloatArraysX100"
- StartTests(TEST_FLOAT_ARRAYS, 100)
- Case "runTestStringArraysX1"
- StartTests(TEST_STRING_ARRAYS, 1)
- Case "runTestStringArraysX25"
- StartTests(TEST_STRING_ARRAYS, 25)
- Case "runTestStringArraysX100"
- StartTests(TEST_STRING_ARRAYS, 100)
- Case "runTestChunkedIntArraysX1"
- StartTests(TEST_CHUNKED_INT_ARRAYS, 1)
- Case "runTestChunkedIntArraysX25"
- StartTests(TEST_CHUNKED_INT_ARRAYS, 25)
- Case "runTestChunkedIntArraysX100"
- StartTests(TEST_CHUNKED_INT_ARRAYS, 100)
- Case "runTestChunkedFloatArraysX1"
- StartTests(TEST_CHUNKED_FLOAT_ARRAYS, 1)
- Case "runTestChunkedFloatArraysX25"
- StartTests(TEST_CHUNKED_FLOAT_ARRAYS, 25)
- Case "runTestChunkedFloatArraysX100"
- StartTests(TEST_CHUNKED_FLOAT_ARRAYS, 100)
- Case "runTestChunkedStringArraysX1"
- StartTests(TEST_CHUNKED_STRING_ARRAYS, 1)
- Case "runTestChunkedStringArraysX25"
- StartTests(TEST_CHUNKED_STRING_ARRAYS, 25)
- Case "runTestChunkedStringArraysX100"
- StartTests(TEST_CHUNKED_STRING_ARRAYS, 100)
- End
- End
- 'internal
- Method StartTests:Void(which:Int, iterations:Int)
- if sessionActive
- AddFail("test already active")
- Else
- AddSuccess("starting tests...")
- sessionActive = True
- sessionWhich = which
- sessionIterations = iterations
- sessionResults = New StringStack()
- sessionCount = 0
- currentTest = TESTS_MIN
- Endif
- End
- Method UpdateTests:Void()
- 'has the session ended?
- If currentTest > TESTS_MAX
- 'session finished, show results
- sessionActive = False
- sessionResults.Push("~ttotal average "+Ceil(Float(sessionCount) / sessionIterations)+" ms")
- #If CERBERUSX
- AddSuccess(TARGET_NAME+" Treebeard Results:")
- #Else
- AddSuccess(TARGET_NAME+" Monkeymaster Results:")
- #Endif
- For Local result := Eachin sessionResults
- AddSuccess(result)
- Next
- Else
- 'session still active
- 'can we run this test or is it ignored?
- If currentTest = sessionWhich Or sessionWhich = TEST_ALL
- If Not currentTestStarted
- 'test not started yet!
- currentTestStarted = True
- currentTestIteration = 1
- currentTestCount = 0
- AddSuccess("running test '"+TEST_LABELS[currentTest]+"' for "+sessionIterations+" iterations...")
- Else
- 'has current test ended?
- if currentTestIteration > sessionIterations
- 'current test finished
- sessionResults.Push("~ttest '"+TEST_LABELS[currentTest]+"' average "+Ceil(Float(currentTestCount) / sessionIterations)+" ms")
- 'next test
- currentTestStarted = False
- currentTest += 1
- Else
- 'current test still running
- AddInfo("#"+currentTestIteration+"")
- Local timestamp := Millisecs()
- Local operations:= 0
- Select currentTest
- Case TEST_INTS
- operations = TestInts()
- Case TEST_FLOATS
- operations = TestFloats()
- Case TEST_STRINGS
- operations = TestStrings()
- Case TEST_INT_ARRAYS
- operations = TestIntArrays()
- Case TEST_FLOAT_ARRAYS
- operations = TestFloatArrays()
- Case TEST_STRING_ARRAYS
- operations = TestStringArrays()
- Case TEST_CHUNKED_INT_ARRAYS
- operations = TestChunkedIntArrays()
- Case TEST_CHUNKED_FLOAT_ARRAYS
- operations = TestChunkedFloatArrays()
- Case TEST_CHUNKED_STRING_ARRAYS
- operations = TestChunkedStringArrays()
- End
- Local took := Millisecs() - timestamp
- AddInfo("executed '"+TEST_LABELS[currentTest]+"' "+operations+" operations, took "+took+" ms")
- currentTestCount += took
- sessionCount += took
- 'next iteration
- currentTestIteration += 1
- Endif
- Endif
- Endif
- Endif
- End
- Method TestInts:Int()
- Local int1 := 0
- Local iterations := INT_ITERATIONS
- Local count := 0
- int1 = 0
- For Local index := 0 Until iterations
- int1 += 2
- count += 1
- if int1 > 1000
- int1 = int1+1
- Endif
- Next
- int1 = 0
- For Local index := 0 Until iterations
- int1 -= 2
- count += 1
- if int1 > 1000
- int1 = int1+1
- Endif
- Next
- int1 = 1
- For Local index := 0 Until iterations
- int1 *= 2
- count += 1
- if int1 > 1000
- int1 = int1+1
- Endif
- Next
- int1 = 1000000
- For Local index := 0 Until iterations
- int1 /= 2
- count += 1
- if int1 > 1000
- int1 = int1+1
- Endif
- Next
- return count
- End
- Method TestFloats:Int()
- Local float1 := 0.0
- Local iterations := FLOAT_ITERATIONS
- Local count := 0
- float1 = 0.0
- For Local index := 0 Until iterations
- float1 += 2.0
- count += 1
- if float1 > 1000.0
- float1 = float1+1
- Endif
- Next
- float1 = 0.0
- For Local index := 0 Until iterations
- float1 -= 2.0
- count += 1
- if float1 > 1000.0
- float1 = float1+1
- Endif
- Next
- float1 = 1.0
- For Local index := 0 Until iterations
- float1 *= 2.0
- count += 1
- if float1 > 1000.0
- float1 = float1+1
- Endif
- Next
- float1 = 1000000.0
- For Local index := 0 Until iterations
- float1 /= 2.0
- count += 1
- if float1 > 1000.0
- float1 = float1+1
- Endif
- Next
- return count
- End
- Method TestStrings:Int()
- Local string1 := ""
- Local iterations := STRING_ITERATIONS
- Local count := 0
- string1 = ""
- For Local index := 0 Until iterations
- string1 = string1+"APPEND"
- count += 1
- Next
- return count
- End
- Method TestIntArrays:Int()
- Local array1:Int[0]
- Local iterations := INT_ARRAY_ITERATIONS
- Local count := 0
- array1 = new Int[0]
- For Local index := 0 Until iterations
- if index = array1.Length
- array1 = array1.Resize(index+1)
- Endif
- array1[index] = count
- count += 1
- Next
- return count
- End
- Method TestFloatArrays:Int()
- Local array1:Float[0]
- Local iterations := FLOAT_ARRAY_ITERATIONS
- Local count := 0
- array1 = new Float[0]
- For Local index := 0 Until iterations
- if index = array1.Length
- array1 = array1.Resize(index+1)
- Endif
- array1[index] = Float(count)+0.345
- count += 1
- Next
- return count
- End
- Method TestStringArrays:Int()
- Local array1:String[0]
- Local iterations := STRING_ARRAY_ITERATIONS
- Local count := 0
- array1 = new String[0]
- For Local index := 0 Until iterations
- if index = array1.Length
- array1 = array1.Resize(index+1)
- Endif
- array1[index] = "value"+count
- count += 1
- Next
- return count
- End
- Method TestChunkedIntArrays:Int()
- Local chunk := CHUNK_SIZE
- Local array1:Int[0]
- Local iterations := INT_ARRAY_ITERATIONS
- Local count := 0
- array1 = new Int[CHUNK_SIZE]
- For Local index := 0 Until iterations
- if count = array1.Length
- array1 = array1.Resize(array1.Length + CHUNK_SIZE)
- Endif
- array1[index] = count
- count += 1
- Next
- 'final trim
- If count < array1.Length
- array1 = array1.Resize(count)
- Endif
- return count
- End
- Method TestChunkedFloatArrays:Int()
- Local chunk := CHUNK_SIZE
- Local array1:Float[0]
- Local iterations := FLOAT_ARRAY_ITERATIONS
- Local count := 0
- array1 = new Float[CHUNK_SIZE]
- For Local index := 0 Until iterations
- if count = array1.Length
- array1 = array1.Resize(array1.Length + CHUNK_SIZE)
- Endif
- array1[index] = Float(count)+0.345
- count += 1
- Next
- 'final trim
- If count < array1.Length
- array1 = array1.Resize(count)
- Endif
- return count
- End
- Method TestChunkedStringArrays:Int()
- Local chunk := CHUNK_SIZE
- Local array1:String[0]
- Local iterations := STRING_ARRAY_ITERATIONS
- Local count := 0
- array1 = new String[CHUNK_SIZE]
- For Local index := 0 Until iterations
- if count = array1.Length
- array1 = array1.Resize(array1.Length + CHUNK_SIZE)
- Endif
- array1[index] = "value"+count
- count += 1
- Next
- 'final trim
- If count < array1.Length
- array1 = array1.Resize(count)
- Endif
- return count
- End
- End
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement