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
5 changes: 3 additions & 2 deletions profile/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ bool unit_test ( const string & fn ) {
return false;
} else {
// cout << *program << "\n";
Context ctx(&str);
Context ctx(&str, 64<<20);
program->simulate(ctx);
// vector of 10000 objects
vector<Object> objects;
Expand Down Expand Up @@ -108,7 +108,8 @@ int main(int argc, const char * argv[]) {
return 0;
#endif
// run tests
run_tests(TEST_PATH "profile", unit_test);
if (argc == 1)
run_tests(TEST_PATH "profile/tests", unit_test);
for ( int i=1; i!=argc; ++i ) {
string path=argv[i];
unit_test(path);
Expand Down
47 changes: 24 additions & 23 deletions profile/fib.das → profile/tests/fib.das
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
// options log=true

def fibR(n:int):int
if (n < 2)
return n
return fibR(n - 1) + fibR(n - 2)

def fibI(n:int):int
let last:int = 0
let cur:int = 1
for i in range(0, n-1)
let tmp:int = cur
cur = last + cur
last = tmp
return cur

def test():bool
profile(4,"fibbonacci loop") <|
fibI(11111134)
profile(1,"fibbonacci recursive") <|
fibR(34)
return true

// options log=true

def fibR(n:int):int
if (n < 2)
return n
else
return fibR(n - 1) + fibR(n - 2)

def fibI(n:int):int
let last:int = 0
let cur:int = 1
for i in range(0, n-1)
let tmp:int = cur
cur += last
last = tmp
return cur

def test():bool
profile(8,"fibbonacci loop") <|
fibI(11111134)
profile(4,"fibbonacci recursive") <|
fibR(34)
return true

29 changes: 29 additions & 0 deletions profile/tests/lua/fibI.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
function fibR(n)

if (n < 2) then return n end
return (fibR(n-2) + fibR(n-1))
end


function fibI(n)

local last = 0
local cur = 1
n = n - 1
while (n > 0)
do
n = n - 1
local tmp = cur
cur = last + cur
last = tmp
end
return cur
end



local start = os.clock()
--N = 34 --Should return 433494437
fibI(11111134)
--print("fib: " .. fibR(N) .. " = " .. fibI(N))
io.write(string.format("elapsed: %.8f\n", os.clock() - start))
32 changes: 32 additions & 0 deletions profile/tests/lua/particles.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
function update_particle(p)
p.pos.x=p.pos.x+p.vel.x
p.pos.y=p.pos.y+p.vel.y
p.pos.z=p.pos.z+p.vel.z
end

function update(particles)
for i,p in ipairs(particles) do
update_particle(p)
end
end

function update_several_times(particles, count)
for i = 0, count do
update(particles)
end
end


particles = {}
for i = 0, 1000000 do
table.insert(particles,
{
pos = {x = i + 0.1, y = i + 0.2, z = i + 0.3},
vel = {x = 1.1, y = 2.1, z = 3.1}
})
end

---
start = os.clock()
update_several_times(particles, 100)
print("took " .. (os.clock()-start))
24 changes: 24 additions & 0 deletions profile/tests/lua/prime.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
function isprime(n)
for i = 2, (n - 1) do
if (n % i == 0) then
return false
end
end
return true
end


function primes(n)
local count = 0

for i = 2, n do
if (isprime(i)) then
count = count + 1
end
end
return count
end


N = 50000
print("primes: " .. primes(N))
26 changes: 13 additions & 13 deletions profile/native.das → profile/tests/native.das
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
require testProfile
def testAdds():int
let count:int = 0
for i in range(0, 100000000)
count = AddOne(count)
return count
def test():bool
profile(1,"native loop") <|
assert(testAdds()==100000000)
return true
require testProfile

def testAdds():int
let count:int = 0
for i in range(0, 100000000)
count = AddOne(count)
return count

def test():bool
profile(1,"native loop") <|
assert(testAdds()==100000000)
return true

32 changes: 32 additions & 0 deletions profile/tests/particles.das
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
require testProfile

struct NObject
position, velocity : float3

def update(a:NObject)
a.position+=a.velocity

def testSim(objects:array<NObject>)
for obj in objects
update(obj)

def testSim2(objects:array<NObject>; count:int)
for i in range(0,count)
testSim(objects)

def init(objects:array<NObject>)
resize(objects, 1000000)
let index:int = 0
for obj in objects
let ( oi:float=float(index++); ii:float=oi*2.0 )
obj.position=float3(oi+0.1,oi+0.2,oi+0.3)
obj.velocity=float3(1.0,2.0,3.0)
assert(index==length(objects))

def test():bool
let objects:array<NObject>
init(objects)
let(total:int=2)
profile(total,"array of nobjects") <|
testSim2(objects,100)
return true
42 changes: 21 additions & 21 deletions profile/primes.das → profile/tests/primes.das
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
def isprime(n:int):bool
for i in range(2, n)
if (n % i == 0)
return false
return true
def primes(n:int):int
let count:int = 0
for i in range(2, n+1)
if (isprime(i))
++count
return count;
def test():bool
profile(2,"primes loop") <|
primes(50000)
return true
def isprime(n:int):bool
for i in range(2, n)
if (n % i == 0)
return false
return true



def primes(n:int):int
let count:int = 0
for i in range(2, n+1)
if (isprime(i))
++count
return count;


def test():bool
profile(2,"primes loop") <|
primes(50000)
return true

Loading