Created
May 12, 2015 10:11
-
-
Save jjatria/2f3fe7e97f5c8caa85fd to your computer and use it in GitHub Desktop.
Compare results of if-blocks and inline-ifs in Praat
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Compare results of if-blocks and inline-ifs in Praat | |
# Author: J J Atria | |
results = Create Table with column names: "table", 0, "sorted branching time" | |
# How long the data set | |
rows = 10000 | |
# How many iterations per data set | |
iterations = 20 | |
for n to iterations | |
selectObject: results | |
Append row | |
row = Object_'results'.nrow | |
table = Create TableOfReal: "table", 10000, 1 | |
Formula: "randomInteger(nrow * -1, nrow)" | |
sorted = 0 | |
@testa() | |
@testb() | |
selectObject: table | |
stopwatch | |
Sort by column: 1, 0 | |
sort = stopwatch | |
sorted = 1 | |
@testa() | |
@testb() | |
removeObject: table | |
endfor | |
procedure testa () | |
stopwatch | |
.sum = 0 | |
for i to Object_'table'.nrow | |
if Object_'table'[i,1] >= 0 | |
.sum += Object_'table'[i,1] | |
endif | |
endfor | |
.time = stopwatch | |
selectObject: results | |
Set numeric value: row, "sorted", sorted | |
Set numeric value: row, "branching", 1 | |
Set numeric value: row, "time", .time | |
endproc | |
procedure testb () | |
stopwatch | |
.sum = 0 | |
for i to Object_'table'.nrow | |
.sum += if Object_'table'[i,1] >= 0 then Object_'table'[i,1] else 0 fi | |
endfor | |
.time = stopwatch | |
selectObject: results | |
Set numeric value: row, "sorted", sorted | |
Set numeric value: row, "branching", 0 | |
Set numeric value: row, "time", .time | |
endproc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment