Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable compression test and log times in CI #222

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions Checker/compression_test.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
open System.Runtime.InteropServices
open System.IO
open System.Text
open System.Diagnostics
open System

#nowarn "51" // use of native pointers

Expand Down Expand Up @@ -38,6 +40,12 @@ let testFiles = [
"yx_long_way_from_home.frag"
]

type CompressionResult = {
minifiedSize: int
compressedSize: float
timeSpan: TimeSpan
}

let writer = new StringWriter()

let log fmt =
Expand All @@ -49,18 +57,20 @@ let log fmt =

let compressionTest args files =
Options.init(args)
let minified =
let stopwatch = Stopwatch.StartNew()
let minified, elapsed =
use out = new StringWriter()
let shaders, exportedNames = ShaderMinifier.minifyFiles [|for f in files -> "tests/real/" + f|]
Formatter.print out shaders exportedNames Options.Text
out.ToString().ToCharArray()
out.ToString().ToCharArray(), stopwatch.Elapsed

let pointer = &&minified.[0]
log "%-40s " (match files with [f] -> f | f::_ -> f + "..." | [] -> "?")
log "%5d " minified.Length
let compressedSize = Crinkler.ApproximateModels4k(pointer, minified.Length)
log "=> %8.3f\n" compressedSize
minified.Length, float compressedSize
printfn "%2.3fs" (float elapsed.TotalMilliseconds / 1000.0)
{ CompressionResult.minifiedSize = minified.Length; compressedSize = float compressedSize; timeSpan = elapsed }

let compressFile (file: string) =
let langArg = if file.EndsWith("hlsl") then [|"--hlsl"|] else [||]
Expand All @@ -79,8 +89,10 @@ let run () =

// Tests for individual files.
let sizes = multifileOutput :: List.map compressFile testFiles
let minifiedSum = List.sumBy fst sizes
let compressedSum = List.sumBy snd sizes
let minifiedSum = sizes |> List.sumBy (fun r -> r.minifiedSize)
let compressedSum = sizes |> List.sumBy (fun r -> r.compressedSize)
let elapsedMilliseconds = sizes |> List.sumBy (fun r -> r.timeSpan.TotalMilliseconds)
log "Total: %5d => %9.3f\n" minifiedSum compressedSum
printfn "in %2.3fs" (elapsedMilliseconds / 1000.0)

File.WriteAllText("tests/compression_results.log", writer.ToString())
4 changes: 2 additions & 2 deletions Checker/main.fs
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ let testGolden () =

[<EntryPoint>]
let main argv =
// Manually run compression tests by enabling this line:
// CompressionTests.run ()
// Manually skip compression tests by disabling this line:
CompressionTests.run ()

initOpenTK()
let mutable failures = testGolden()
Expand Down