-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #202 from gudzpoz/reflection
- fix: try to load class from multiple class-loaders - perf: cache reflection results
- Loading branch information
Showing
12 changed files
with
523 additions
and
87 deletions.
There are no files selected for viewing
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
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
52 changes: 52 additions & 0 deletions
52
example/src/jmh/java/party/iroiro/luajava/jmh/MethodCallBenchmark.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package party.iroiro.luajava.jmh; | ||
|
||
import org.openjdk.jmh.annotations.*; | ||
import party.iroiro.luajava.Lua; | ||
import party.iroiro.luajava.lua54.Lua54; | ||
import party.iroiro.luajava.luaj.LuaJ; | ||
import party.iroiro.luajava.luajit.LuaJit; | ||
|
||
import java.math.BigInteger; | ||
|
||
@State(Scope.Benchmark) | ||
public class MethodCallBenchmark { | ||
|
||
@Param({"Lua 5.4", "LuaJIT", "LuaJ"}) | ||
public String lua; | ||
|
||
private Lua L; | ||
|
||
@Setup | ||
public void setup() { | ||
switch (lua) { | ||
case "Lua 5.4": | ||
L = new Lua54(); | ||
break; | ||
case "LuaJIT": | ||
L = new LuaJit(); | ||
break; | ||
case "LuaJ": | ||
L = new LuaJ(); | ||
break; | ||
default: | ||
throw new IllegalStateException(); | ||
} | ||
L.set("big_int", BigInteger.valueOf(1024)); | ||
L.run("int_value = java.method(big_int, 'intValue', '')"); | ||
} | ||
|
||
@Benchmark | ||
public void benchmarkObjectMethodCall() { | ||
L.run("assert(big_int:intValue() == 1024)"); | ||
} | ||
|
||
@Benchmark | ||
public void benchmarkModuleMethodCall() { | ||
L.run("assert(int_value() == 1024)"); | ||
} | ||
|
||
@TearDown | ||
public void tearDown() { | ||
L.close(); | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
example/src/jmh/java/party/iroiro/luajava/jmh/SimpleBenchmark.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package party.iroiro.luajava.jmh; | ||
|
||
import org.openjdk.jmh.annotations.*; | ||
import party.iroiro.luajava.ClassPathLoader; | ||
import party.iroiro.luajava.Lua; | ||
import party.iroiro.luajava.lua54.Lua54; | ||
import party.iroiro.luajava.luaj.LuaJ; | ||
import party.iroiro.luajava.luajit.LuaJit; | ||
|
||
@State(Scope.Benchmark) | ||
public class SimpleBenchmark { | ||
|
||
private void setupLua(Lua L) { | ||
L.openLibraries(); | ||
L.run("io.write = function(s) assert(string.find(s, 'tree', 1, true)) end"); | ||
L.setExternalLoader(new ClassPathLoader()); | ||
L.loadExternal("binary-trees"); | ||
L.setGlobal("benchmark"); | ||
} | ||
|
||
@Param({"Lua 5.4", "LuaJIT", "LuaJ"}) | ||
public String lua; | ||
|
||
private Lua L; | ||
|
||
@Setup | ||
public void setup() { | ||
switch (lua) { | ||
case "Lua 5.4": | ||
L = new Lua54(); | ||
break; | ||
case "LuaJIT": | ||
L = new LuaJit(); | ||
break; | ||
case "LuaJ": | ||
L = new LuaJ(); | ||
break; | ||
default: | ||
throw new IllegalStateException(); | ||
} | ||
setupLua(L); | ||
} | ||
|
||
@Benchmark | ||
public void benchmarkBinaryTrees() { | ||
L.run("benchmark()"); | ||
} | ||
|
||
@TearDown | ||
public void tearDown() { | ||
L.close(); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
-- Copyright © 2004-2008 Brent Fulgham, 2005-2024 Isaac Gouy | ||
-- All rights reserved. | ||
-- | ||
-- Redistribution and use in source and binary forms, with or without | ||
-- modification, are permitted provided that the following conditions are met: | ||
-- | ||
-- 1. Redistributions of source code must retain the above copyright notice, | ||
-- this list of conditions and the following disclaimer. | ||
-- | ||
-- 2. Redistributions in binary form must reproduce the above copyright notice, | ||
-- this list of conditions and the following disclaimer in the documentation | ||
-- and/or other materials provided with the distribution. | ||
-- | ||
-- 3. Neither the name "The Computer Language Benchmarks Game" nor the name "The | ||
-- Benchmarks Game" nor the name "The Computer Language Shootout Benchmarks" nor | ||
-- the names of its contributors may be used to endorse or promote products | ||
-- derived from this software without specific prior written permission. | ||
-- | ||
|
||
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
-- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
-- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
-- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | ||
-- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
-- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
-- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
-- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
-- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
-- POSSIBILITY OF SUCH DAMAGE. | ||
|
||
-- The Computer Language Benchmarks Game | ||
-- https://salsa.debian.org/benchmarksgame-team/benchmarksgame/ | ||
-- contributed by Mike Pall | ||
-- *reset* | ||
|
||
local function BottomUpTree(depth) | ||
if depth > 0 then | ||
depth = depth - 1 | ||
local left, right = BottomUpTree(depth), BottomUpTree(depth) | ||
return { left, right } | ||
else | ||
return { } | ||
end | ||
end | ||
|
||
local function ItemCheck(tree) | ||
if tree[1] then | ||
return 1 + ItemCheck(tree[1]) + ItemCheck(tree[2]) | ||
else | ||
return 1 | ||
end | ||
end | ||
|
||
local N = tonumber(arg and arg[1]) or 0 | ||
local mindepth = 4 | ||
local maxdepth = mindepth + 2 | ||
if maxdepth < N then maxdepth = N end | ||
|
||
do | ||
local stretchdepth = maxdepth + 1 | ||
local stretchtree = BottomUpTree(stretchdepth) | ||
io.write(string.format("stretch tree of depth %d\t check: %d\n", | ||
stretchdepth, ItemCheck(stretchtree))) | ||
end | ||
|
||
local longlivedtree = BottomUpTree(maxdepth) | ||
|
||
for depth=mindepth,maxdepth,2 do | ||
local iterations = 2 ^ (maxdepth - depth + mindepth) | ||
local check = 0 | ||
for i=1,iterations do | ||
check = check + ItemCheck(BottomUpTree(depth)) | ||
end | ||
io.write(string.format("%d\t trees of depth %d\t check: %d\n", | ||
iterations, depth, check)) | ||
end | ||
|
||
io.write(string.format("long lived tree of depth %d\t check: %d\n", | ||
maxdepth, ItemCheck(longlivedtree))) |
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
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
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
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
Oops, something went wrong.