Created
February 5, 2015 14:39
-
-
Save hjanuschka/9d097808eb7734627a9e to your computer and use it in GitHub Desktop.
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
<? | |
$res = bartlby_new("/opt/bartlby/etc/bartlby.cfg"); | |
include "config.php"; | |
include "bartlby-ui.class.php"; | |
$btl=new BartlbyUi($Bartlby_CONF, false); | |
$l = new lua(); | |
$l->eval(<<<CODE | |
-- save a pointer to globals that would be unreachable in sandbox | |
local e=_ENV | |
-- sample sandbox environment | |
sandbox_env = { | |
ipairs = ipairs, | |
next = next, | |
pairs = pairs, | |
pcall = pcall, | |
tonumber = tonumber, | |
tostring = tostring, | |
type = type, | |
unpack = unpack, | |
coroutine = { create = coroutine.create, resume = coroutine.resume, | |
running = coroutine.running, status = coroutine.status, | |
wrap = coroutine.wrap }, | |
string = { byte = string.byte, char = string.char, find = string.find, | |
format = string.format, gmatch = string.gmatch, gsub = string.gsub, | |
len = string.len, lower = string.lower, match = string.match, | |
rep = string.rep, reverse = string.reverse, sub = string.sub, | |
upper = string.upper }, | |
table = { insert = table.insert, maxn = table.maxn, remove = table.remove, | |
sort = table.sort }, | |
math = { abs = math.abs, acos = math.acos, asin = math.asin, | |
atan = math.atan, atan2 = math.atan2, ceil = math.ceil, cos = math.cos, | |
cosh = math.cosh, deg = math.deg, exp = math.exp, floor = math.floor, | |
fmod = math.fmod, frexp = math.frexp, huge = math.huge, | |
ldexp = math.ldexp, log = math.log, log10 = math.log10, max = math.max, | |
min = math.min, modf = math.modf, pi = math.pi, pow = math.pow, | |
rad = math.rad, random = math.random, sin = math.sin, sinh = math.sinh, | |
sqrt = math.sqrt, tan = math.tan, tanh = math.tanh }, | |
os = { clock = os.clock, difftime = os.difftime, time = os.time }, | |
} | |
function run_sandbox(sb_env, sb_func, ...) | |
local sb_orig_env=_ENV | |
if (not sb_func) then return nil end | |
_ENV=sb_env | |
local sb_ret={e.pcall(sb_func, ...)} | |
_ENV=sb_orig_env | |
return e.table.unpack(sb_ret) | |
end | |
function my_eval(expr) | |
if(expr) | |
then | |
return 1 | |
else | |
return 0 | |
end | |
end | |
CODE | |
); | |
$time_start = microtime_float(); | |
$searched = 0; | |
$matched=0; | |
for($y=0; $y<1000; $y++ ) { | |
for($x=0; $x<10;$x++) { | |
$s = bartlby_get_service($res, $x); | |
$l->assign("service", $s); | |
$r = 0; | |
try { | |
$r=$l->eval("my_eval(" . $argv[1] . ")"); | |
} catch(Exception $ex) { | |
/// | |
$r=0; | |
//var_dump($ex); | |
} | |
if($r == 1) { | |
//echo $s["server_name"] . "/" . $s["service_name"] . "-" . $s["plugin"] . " - matched\n"; | |
$matched++; | |
} | |
$searched++; | |
} | |
} | |
echo $searched . " matched: " . $matched; | |
$time_end = microtime_float(); | |
$time = $time_end - $time_start; | |
echo "Lua Time: $time\n"; | |
$time_start = microtime_float(); | |
$searched = 0; | |
$matched=0; | |
for($y=0; $y<1000; $y++ ) { | |
for($x=0; $x<10;$x++) { | |
$s = bartlby_get_service($res, $x); | |
if($btl->bartlby_service_matches_string($svc, "service_name = 'Load'")) { | |
$matched++; | |
} | |
$searched++; | |
} | |
} | |
echo $searched . " matched: " . $matched; | |
$time_end = microtime_float(); | |
$time = $time_end - $time_start; | |
echo "Core Time: $time\n"; | |
function microtime_float() | |
{ | |
list($usec, $sec) = explode(" ", microtime()); | |
return ((float)$usec + (float)$sec); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment