Skip to content

Instantly share code, notes, and snippets.

@sepbot
Created May 4, 2021 10:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sepbot/d2a90613bf0c257e489376cf50ec9002 to your computer and use it in GitHub Desktop.
Save sepbot/d2a90613bf0c257e489376cf50ec9002 to your computer and use it in GitHub Desktop.
graal execute python
val ctx = Context.newBuilder()
.allowAllAccess(true)
.build()
@Language("Python") val script = """
import polyglot
@polyglot.export_value
def main(x):
return x + 1
""".trimIndent()
println(measureNanoTime { ctx.eval("python", script) })
val random = Random(System.currentTimeMillis())
for (i in 1..10) {
println(measureNanoTime { ctx.polyglotBindings.getMember("main").execute(random.nextInt()) })
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment