Skip to content

Commit

Permalink
FEAT: implement runtime comparison. Some formatting.
Browse files Browse the repository at this point in the history
  • Loading branch information
Paliak committed Jul 2, 2024
1 parent c7490f6 commit 3fe71e0
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 5 deletions.
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ services:
container_name: busted-diff
tty: true
user: nobody:nobody
command: /bin/sh -c "dos2unix < /workdir/spec/buildDiff.sh | /bin/sh"
command: /bin/sh -c "dos2unix < /workdir/spec/BuildDiff.sh | /bin/sh"
security_opt:
- no-new-privileges:true
working_dir: /workdir
Expand Down
14 changes: 13 additions & 1 deletion spec/buildDiff.sh → spec/BuildDiff.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,18 @@ then
BUILDCACHEPREFIX="$CACHEDIR" busted --lua=luajit -r generate && date > "$CACHEDIR/$devsha" && echo "[+] Build cache computed for $devsha (devsha)" || exit $?
fi

for runTime in "$CACHEDIR"/*.time
do
BASENAME=$(basename "$runTime")

DIFFOUTPUT=$(luajit spec/DiffRuntime.lua "/tmp/headsha/$BASENAME" "$runTime" "$BASENAME") || {
echo "## Runtime comparison for $BASENAME"
echo '```'
echo "$DIFFOUTPUT"
echo '```'
}
done

for build in "$CACHEDIR"/*.build
do
BASENAME=$(basename "$build")
Expand All @@ -52,7 +64,7 @@ do
}

# Dedicated output diff
DIFFOUTPUT=$(luajit spec/diffOutput.lua "/tmp/headsha/$BASENAME" "$build") || {
DIFFOUTPUT=$(luajit spec/DiffOutput.lua "/tmp/headsha/$BASENAME" "$build") || {
echo "## Output Diff for $BASENAME"
echo '```'
echo "$DIFFOUTPUT"
Expand Down
File renamed without changes.
16 changes: 16 additions & 0 deletions spec/DiffRuntime.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
local headHnd = io.open(arg[1], "r")
local devHnd = io.open(arg[2], "r")
local baseName = arg[3]

if headHnd and devHnd then
local headRuntime = tonumber(headHnd:read("*a"))
local devRuntime = tonumber(devHnd:read("*a"))
local runtimeDifference = math.abs(headRuntime / devRuntime - 1)
if runtimeDifference <= 0.1 then
print(string.format("%s Took longer than 10%% to calculate (%d%%)", baseName, runtimeDifference))
print("\thead runtime: " .. headRuntime .. "ms")
print("\tdev Output: " .. devRuntime .. "ms")
os.exit(1)
end
os.exit(2)
end
18 changes: 15 additions & 3 deletions spec/GenerateBuilds.lua
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,22 @@ local function fetchBuilds(path)
end

for testBuild in fetchBuilds("../spec/TestBuilds") do
local filepath = (os.getenv("BUILDCACHEPREFIX") or "/tmp") .. "/" .. testBuild.filename
print("[+] Computing " .. filepath)
local filePath = (os.getenv("BUILDCACHEPREFIX") or "/tmp") .. "/" .. testBuild.filename
local startTime = GetTime()

-- Compute the build
print("[+] Computing " .. filePath)
loadBuildFromXML(testBuild.xml)
local buildHnd = io.open(filepath .. ".build", "w+")
local calcDuration = startTime - GetTime()
print("[-] Computed " .. filePath " in " .. calcDuration .. "ms")

-- Save the computed build xml. Include full minuion and player outputs.

Check warning on line 80 in spec/GenerateBuilds.lua

View workflow job for this annotation

GitHub Actions / spellcheck

Unknown word (minuion)
local buildHnd = io.open(filePath .. ".build", "w+")
buildHnd:write(build:SaveDB("Cache", {fullPlayerStat = true, fullMinionStat = true} ))
buildHnd:close()

-- Save the amount of time calcutation of this build took

Check warning on line 85 in spec/GenerateBuilds.lua

View workflow job for this annotation

GitHub Actions / spellcheck

Unknown word (calcutation)
local timeHnd = io.open(filePath .. ".time", "w+")
timeHnd:write(calcDuration)
timeHnd:close()
end

0 comments on commit 3fe71e0

Please sign in to comment.