Created
May 4, 2021 10:42
-
-
Save sepbot/d2a90613bf0c257e489376cf50ec9002 to your computer and use it in GitHub Desktop.
graal execute python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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