Skip to content

Instantly share code, notes, and snippets.

@caesaneer
Created August 16, 2019 04:44
Show Gist options
  • Save caesaneer/99a9583abc1600214aa827a1e49013c3 to your computer and use it in GitHub Desktop.
Save caesaneer/99a9583abc1600214aa827a1e49013c3 to your computer and use it in GitHub Desktop.
Fibonacci
package ktor.benchmark
/* ktlint-disable no-wildcard-imports */
import io.ktor.application.*
import io.ktor.response.*
import io.ktor.request.*
import io.ktor.routing.*
import io.ktor.http.*
import io.ktor.locations.*
/* ktlint-enable no-wildcard-imports */
fun main(args: Array<String>): Unit = io.ktor.server.netty.EngineMain.main(args)
@Suppress("unused") // Referenced in application.conf
fun Application.module() {
install(Locations)
routing {
get("/") {
// var result = LongArray(90001)
fib()
// var r = fib()
// println(r.size)
call.respondText("OK", contentType = ContentType.Text.Plain, status = HttpStatusCode.OK)
}
}
}
fun fib(): LongArray {
var result = LongArray(100000)
var counter = 0
var start = 1000
while (start >= 1) {
var num = 90
var n1: Long = 0
var n2: Long = 1
var temp: Long = 0
while (num >= 1) {
temp = n2
n2 = n1 + n2
n1 = temp
result.set(counter, n2.toLong())
counter++
num--
}
start--
}
return result
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment