Skip to content

Commit

Permalink
Merge branch 'feature/fasteffekt-list' into feature/fasteffekt
Browse files Browse the repository at this point in the history
  • Loading branch information
IR0NSIGHT committed Nov 6, 2023
2 parents cc66437 + b0c5c3d commit d7184ba
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 3 deletions.
12 changes: 9 additions & 3 deletions examples/fasteffekt/harness.effekt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module examples/fasteffekt/harness


import examples/fasteffekt/permute
import examples/fasteffekt/list
import io/args
import text/string

Expand Down Expand Up @@ -56,16 +57,17 @@ def doRuns(innerIterations: Int, iterations: Int){benchmark: Int=>Unit} = {
def doBenchmark(name: String, inner: Int, iterations: Int) = {
if (name == "Permute") {
doRuns(inner, iterations){Permute}
} else if (name == "List") {
doRuns(inner, iterations){List}
} else {
panic("unknown benchmark")
}
}

def main() = {
def attemptBenchmarkExec(args: List[String]) = {
val debugStartTime : Int = currentTimeNanos();


["Permute","100", "100"] match {
args match {
case Cons(x, Cons(y, Cons(z, Nil()))) =>
(x, toInt(y), toInt(z)) match {
case (benchName, Some(iterations), Some(innerIterations)) =>
Expand All @@ -80,3 +82,7 @@ def main() = {
println("DEBUG: runner total took: " ++ show(runTime) ++ " us");
}

def main() = {
attemptBenchmarkExec(["List","100", "100"])
}

81 changes: 81 additions & 0 deletions examples/fasteffekt/list.effekt
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import examples/fasteffekt/benchmark

record Element (
value: Int, child: Option[Element]
)

def length(element: Option[Element]): Int =
element match {
case None() => return 0;
case Some(Element(value, child)) => return 1 + length(child)
}

def isShorterThan(x: Option[Element], y: Option[Element]): Boolean = {
var xTail:Option[Element] = x;
var yTail:Option[Element] = y;
var run = true;
var bigger = false;
while (run) {
(xTail,yTail) match {
case (_, None()) => run = false; bigger = false;
case (None(), _) => run =false; bigger = true;
case (Some(xx),Some(yy)) => xTail = xx.child; yTail = yy.child;
}
}
return bigger;
}

def makeList(lenght: Int): Option[Element] = {
return if(lenght == 0) {
None()
} else {
Some(Element(0, makeList(lenght-1)))
}
}

//no idea what that function does.
def tail(x: Option[Element], y: Option[Element], z: Option[Element]): Option[Element] = {
if (y.isShorterThan(x)) {
(x,y,z) match {
case (Some(xx),Some(yy),Some(zz)) =>
val yChild : Option[Element] = yy.child;
val zChild : Option[Element] = zz.child;
val xChild : Option[Element] = xx.child;

val xxx: Option[Element] = tail(xChild, y, z);
val yyy: Option[Element] = tail(yChild, z, x);
val zzz: Option[Element] = tail(zChild, x, y);
tail(
xxx,
yyy,
zzz
)
case _ => panic("oh no!");
}
} else {
z;
}
}

def List(_: Int) = {
def benchmark(): Int = {
val result =
tail(
makeList(15),
makeList(10),
makeList(6)
);
length(result);
}


def verifyResult(result: Int): Boolean = {
return result == 10;
}

return innerBenchmarkLoop(1){benchmark}{verifyResult};
}

def main() = {
List(0);
}

0 comments on commit d7184ba

Please sign in to comment.