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
6 changes: 3 additions & 3 deletions examples/profile/extra_test/hybrid.das
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ def fibRH(n)
[export]
def main
var f1 = 0
profile(20,"fibbonacci recursive") <|
profile(20,"fibonacci recursive") <|
f1 = fibR(31)
assert(f1==1346269)
var f2 = 0
profile(20,"fibbonacci recursive, no aot") <|
profile(20,"fibonacci recursive, no aot") <|
f2 = fibRNA(31)
assert(f2==1346269)
var f3 = 0
profile(20,"fibbonacci recursive, hybrid") <|
profile(20,"fibonacci recursive, hybrid") <|
f3 = fibRH(31)
assert(f3==1346269)

Expand Down
12 changes: 10 additions & 2 deletions examples/profile/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,16 @@ int main(int argc, char * argv[]) {
vector<const char *> newArgv;
newArgv.push_back(argv[0]);
newArgv.push_back(dasRoot.c_str());
newArgv.push_back("-jit");
newArgv.push_back("--");
bool noJIT = false;
for ( int i=1; i<argc; ++i ) {
if ( strcmp(argv[i],"-html")==0 ) {
noJIT = true;
}
}
if ( !noJIT ) {
newArgv.push_back("-jit");
newArgv.push_back("--");
}
for ( int i=1; i<argc; ++i ) {
newArgv.push_back(argv[i]);
}
Expand Down
157 changes: 146 additions & 11 deletions examples/profile/main.das
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require daslib/strings_boost
require fio
require strings
require rtti
require debugapi
require math
Expand All @@ -8,7 +8,6 @@ var LOG_TEST_COMPILATION_TIME = false

var failed = 0

[no_jit]
def compile_and_run ( fileName:string; useAot:bool; useJit:bool )
var t0 = ref_time_ticks()
var inscope access <- make_file_access("")
Expand Down Expand Up @@ -46,9 +45,12 @@ def compile_and_run ( fileName:string; useAot:bool; useJit:bool )
failed ++


[no_jit]
def test_single_file ( fileName:string )
// print("{fileName}\n")
/*
if!(fileName |> ends_with("dict.das") || fileName |> ends_with("exp.das"))
return
*/
print("\"DAS AOT\", ")
compile_and_run(fileName, true, false)
print("\"DAS JIT\", ")
Expand All @@ -57,14 +59,143 @@ def test_single_file ( fileName:string )
compile_and_run(fileName, false, false)
print("\n\n")

[no_jit]
def run_dir ( appDir : string )
dir(appDir) <| $ ( fileName )
if (!fileName |> starts_with("_")) && fileName |> ends_with(".das")
let appfile = "{appDir}/{fileName}"
test_single_file(appfile)

[export,no_jit]
struct ProfileEntry
language : string
category : string
time : double
count : int

enum ParseProfileEntryError
Ok
InvalidInput
InvalidLanguage
InvalidCategory
InvalidTime
InvalidCount

[no_jit,no_aot]
def parse_profile_entry ( invocation:string; blk : block<(res:ProfileEntry):void> ) : ParseProfileEntryError
var sub <- invocation |> split(",")
if length(sub)!=4
return ParseProfileEntryError InvalidInput
for s in sub
s = s |> trim
var language = sub[0]
if language |> starts_with("\"") && language |> ends_with("\"")
language = language |> slice(1, -1)
else
return ParseProfileEntryError InvalidLanguage
var category = sub[1]
if category |> starts_with("\"") && category |> ends_with("\"")
category = category |> slice(1, -1)
else
return ParseProfileEntryError InvalidCategory
var time = DBL_MAX
try
time = double(sub[2])
recover
pass
if time == DBL_MAX
return ParseProfileEntryError InvalidTime
var count = INT_MAX
try
count = int(sub[3])
recover
pass
if count == INT_MAX
return ParseProfileEntryError InvalidCount
blk |> invoke([[ProfileEntry language=language, category=category, time=time, count=count]])
return ParseProfileEntryError Ok

def make_table ( tablename:string; entries:array<ProfileEntry>; languages:table<string> )
var categories : table<string; double>
for e in entries
if languages |> key_exists(e.language)
if categories |> key_exists(e.category)
categories[e.category] = min(e.time, categories[e.category])
else
categories[e.category] = e.time
var slanguages <- [{for l in keys(languages); l}]
slanguages |> sort
var scategories <- [{for c in keys(categories); c}]
scategories |> sort
print("<h2>{tablename}</h2>\n")
print("<table border=\"1\">\n")
print("<tr><th>Language</th>\n")
for c in scategories
print("<th>{c}<br>times slower</th>")
print("</tr>\n")
for l in slanguages
// collect times for each category given language
var cattime : table<string; double>
for e in entries
if e.language == l
cattime[e.category] = e.time
// print category times of specific language
print("<tr><td>{l}</td>\n")
for c in scategories
if cattime |> key_exists(c)
let time = cattime[c]
let mintime = categories[c]
let factor = time / mintime
let ts = format("%.4f", float(time))
let fs = format("%.2f", float(factor))
if time == mintime
print("<td><b>{fs} ({ts})</b></td>")
else
print("<td>{fs} ({ts})</td>")
else
print("<td>0</td>")
print("</tr>\n")
print("</table>\n")

def make_html
let exe = get_command_line_arguments()[0]
let cmdLine = "{exe}"
var entries : array<ProfileEntry>
unsafe
var exitCode = popen(cmdLine) <| $ ( f )
while !feof(f)
let st = fgets(f)
let err = parse_profile_entry(st) <| $ ( res )
entries |> push(res)
print("{res}\n")
if err != ParseProfileEntryError Ok
print(st)
if exitCode != 0
print("Error: {exitCode}\n")
return
print("<!DOCTYPE html><html>\n")
print("<body>\n")
make_table("interpreted", entries, {{
"DAS INTERPRETER";
"MONO --interpreter";
"LUAU";
"LUA";
"LUAJIT -joff";
"SQUIRREL3";
"QUIRREL";
"QUICKJS";
}})
make_table("AOT or JIT", entries, {{
"DAS AOT";
"DAS JIT";
"C++";
"MONO";
".NET";
"LUAJIT";
"LUAU --codegen";
}})
print("</body>\n")
print("</html>\n")

[export]
def main
var singleTest = ""
var mainTests = true
Expand All @@ -74,19 +205,23 @@ def main
let nArgs = get_command_line_arguments() |> length()
var i = 0
while i < nArgs
if get_command_line_arguments()[i]=="-test" && i < nArgs-1
let arg = get_command_line_arguments()[i]
if arg=="-test" && i < nArgs-1
singleTest = get_command_line_arguments()[i+1]
i += 2
continue
elif get_command_line_arguments()[i]=="-log"
elif arg=="-html"
make_html()
return
elif arg=="-log"
LOG_TEST_COMPILATION_TIME = true
elif get_command_line_arguments()[i]=="-extra"
elif arg=="-extra"
extraTests = true
elif get_command_line_arguments()[i]=="-hash"
elif arg=="-hash"
hashTests = true
elif get_command_line_arguments()[i]=="-nomain"
elif arg=="-nomain"
mainTests = false
elif get_command_line_arguments()[i]=="-help"
elif arg=="-help"
print("Usage: profile_tests [-test <testname>] [-log] [-extra] [-hash]\n")
print(" -test testname runs /examples/profile/tests/test.das and exits immediately\n")
print(" -log logs compilation time\n")
Expand Down
2 changes: 1 addition & 1 deletion examples/profile/tests/cs/dict.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ static void profile ( int count, string category, MyBlock f ) {
double dt = ((double)elapsed.TotalMilliseconds) / 1000.0;
minT = Math.Min(minT, dt);
}
Console.WriteLine("\"" + category + "\"," + minT + ", " + count);
Console.WriteLine($"\"{category}\", {minT}, {count}");
}

public static void MakeRandomSequence(ref string[] src)
Expand Down
2 changes: 1 addition & 1 deletion examples/profile/tests/cs/exp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ static void profile ( int count, string category, MyBlock f ) {
double dt = ((double)elapsed.TotalMilliseconds) / 1000.0;
minT = Math.Min(minT, dt);
}
Console.WriteLine("\"" + category + "\"," + minT + ", " + count);
Console.WriteLine($"\"{category}\", {minT}, {count}");
}

// Translated expLoop function
Expand Down
4 changes: 2 additions & 2 deletions examples/profile/tests/cs/fib_loop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ static void profile ( int count, string category, MyBlock f ) {
double dt = ((double)elapsed.TotalMilliseconds) / 1000.0;
minT = Math.Min(minT, dt);
}
Console.WriteLine("\"" + category + "\"," + minT + ", " + count);
Console.WriteLine($"\"{category}\", {minT}, {count}");
}

public static int FibI(int n)
Expand All @@ -35,7 +35,7 @@ public static int FibI(int n)
return cur;
}
static void Main() {
profile(20, "fibbonacci loop", () => {
profile(20, "fibonacci loop", () => {
int fi = FibI(6511134);
Debug.Assert( fi==1781508648, "The result is incorrect.");
});
Expand Down
4 changes: 2 additions & 2 deletions examples/profile/tests/cs/fib_recursive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ static void profile ( int count, string category, MyBlock f ) {
double dt = ((double)elapsed.TotalMilliseconds) / 1000.0;
minT = Math.Min(minT, dt);
}
Console.WriteLine("\"" + category + "\"," + minT + ", " + count);
Console.WriteLine($"\"{category}\", {minT}, {count}");
}

public static int FibR(int n)
Expand All @@ -30,7 +30,7 @@ public static int FibR(int n)
}

static void Main() {
profile(20, "fibbonacci recursive", () => {
profile(20, "fibonacci recursive", () => {
int fi = FibR(31);
Debug.Assert( fi==1346269, "The result is incorrect.");
});
Expand Down
4 changes: 2 additions & 2 deletions examples/profile/tests/cs/nbodies.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,12 @@ static void profile ( int count, string category, MyBlock f ) {
double dt = ((double)elapsed.TotalMilliseconds) / 1000.0;
minT = Math.Min(minT, dt);
}
Console.WriteLine("\"" + category + "\"," + minT + ", " + count);
Console.WriteLine($"\"{category}\", {minT}, {count}");
}
static void Main() {
NBodySystem bodies = new NBodySystem();
double e1 = bodies.Energy();
profile(10, "nbodies", () => {
profile(10, "n-bodies", () => {
for (int i = 0; i < 500000; i++) {
bodies.Advance(1.0);
}
Expand Down
4 changes: 2 additions & 2 deletions examples/profile/tests/cs/particles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ static void profile ( int count, string category, MyBlock f ) {
double dt = ((double)elapsed.TotalMilliseconds) / 1000.0;
minT = Math.Min(minT, dt);
}
Console.WriteLine("\"" + category + "\"," + minT + ", " + count);
Console.WriteLine($"\"{category}\", {minT}, {count}");
}

struct Vector3
Expand Down Expand Up @@ -83,7 +83,7 @@ static NObject[] Init()

static void Main() {
var objects = Init();
profile(20, "particles kinematics, inlined", () => {
profile(20, "particles kinematics", () => {
TestSim2I(objects, 100);
});
float f = 0;
Expand Down
2 changes: 1 addition & 1 deletion examples/profile/tests/cs/primes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ static void profile ( int count, string category, MyBlock f ) {
double dt = ((double)elapsed.TotalMilliseconds) / 1000.0;
minT = Math.Min(minT, dt);
}
Console.WriteLine("\"" + category + "\"," + minT + ", " + count);
Console.WriteLine($"\"{category}\", {minT}, {count}");
}

// Check if a number is prime
Expand Down
2 changes: 1 addition & 1 deletion examples/profile/tests/cs/sha256.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ static void profile(int count, string category, MyBlock f)
double dt = ((double)elapsed.TotalMilliseconds) / 1000.0;
minT = Math.Min(minT, dt);
}
Console.WriteLine("\"" + category + "\"," + minT + ", " + count);
Console.WriteLine($"\"{category}\", {minT}, {count}");
}

private static readonly uint[] primes =
Expand Down
2 changes: 1 addition & 1 deletion examples/profile/tests/cs/tree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ static void profile ( int count, string category, MyBlock f ) {
double dt = ((double)elapsed.TotalMilliseconds) / 1000.0;
minT = Math.Min(minT, dt);
}
Console.WriteLine("\"" + category + "\"," + minT + ", " + count);
Console.WriteLine($"\"{category}\", {minT}, {count}");
}

public class Node {
Expand Down
6 changes: 3 additions & 3 deletions examples/profile/tests/dict.das
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ def main
luaFile = "dict.lua",
luaJitFile = "dict.lua",
nutFile = "dict.nut",
nutModifiedFile = "dict.nut",
// asFile = "dict.as", // TODO: update AS to new version?
jsFile = "dict.js",
monoFile = "dict.cs"
monoFile = "dict.cs",
dotNetFile = "dict.cs",
]])


4 changes: 3 additions & 1 deletion examples/profile/tests/exp.das
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ def main
luaFile = "exp.lua",
luaJitFile = "exp.lua",
nutFile = "exp.nut",
nutModifiedFile = "exp.nut",
// asFile = "exp.as", // TODO: implement
jsFile = "exp.js",
monoFile = "exp.cs"
monoFile = "exp.cs",
dotNetFile = "exp.cs",
]])
Loading