@@ -27,82 +27,84 @@ interface NativeTiming extends Timing {
2727 endToEndMs : number ;
2828}
2929
30- await mkdir ( data , { recursive : true } ) ;
31- await exec ( "pnpm" , [ "tsx" , "tools/generate-benchmark-fixture.ts" , fixture ] , {
32- cwd : root ,
33- } ) ;
34- await exec ( "cargo" , [ "build" , "--release" , "-p" , "demucs-cli" ] , {
35- cwd : root ,
36- } ) ;
30+ async function main ( ) {
31+ await mkdir ( data , { recursive : true } ) ;
32+ await exec ( "pnpm" , [ "tsx" , "tools/generate-benchmark-fixture.ts" , fixture ] , {
33+ cwd : root ,
34+ } ) ;
35+ await exec ( "cargo" , [ "build" , "--release" , "-p" , "demucs-cli" ] , {
36+ cwd : root ,
37+ } ) ;
38+
39+ const nativeRuns : NativeTiming [ ] = [ ] ;
40+ for ( let index = 0 ; index <= measuredRuns ; index ++ ) {
41+ const runDir = resolve ( data , `native-run-${ index } ` ) ;
42+ const timings = resolve ( data , `native-run-${ index } .json` ) ;
43+ await rm ( runDir , { recursive : true , force : true } ) ;
44+ await exec (
45+ binary ,
46+ [
47+ "separate" ,
48+ "--models" ,
49+ models ,
50+ "--timings-json" ,
51+ timings ,
52+ fixture ,
53+ runDir ,
54+ ] ,
55+ { cwd : root , maxBuffer : 10 * 1024 * 1024 } ,
56+ ) ;
57+ const result = JSON . parse ( await readFile ( timings , "utf8" ) ) as Omit <
58+ NativeTiming ,
59+ "endToEndMs"
60+ > ;
61+ if ( index > 0 ) {
62+ nativeRuns . push ( {
63+ ...result ,
64+ endToEndMs : result . totalMs ,
65+ totalMs :
66+ result . prepareMs +
67+ result . loadMs +
68+ result . inferenceMs +
69+ result . finalizeMs ,
70+ } ) ;
71+ }
72+ }
73+ await writeFile (
74+ resolve ( data , "native.json" ) ,
75+ JSON . stringify ( { backend : "native" , runs : nativeRuns } , null , 2 ) ,
76+ ) ;
3777
38- const nativeRuns : NativeTiming [ ] = [ ] ;
39- for ( let index = 0 ; index <= measuredRuns ; index ++ ) {
40- const runDir = resolve ( data , `native-run-${ index } ` ) ;
41- const timings = resolve ( data , `native-run-${ index } .json` ) ;
42- await rm ( runDir , { recursive : true , force : true } ) ;
4378 await exec (
44- binary ,
45- [
46- "separate" ,
47- "--models" ,
48- models ,
49- "--timings-json" ,
50- timings ,
51- fixture ,
52- runDir ,
53- ] ,
79+ "pnpm" ,
80+ [ "-C" , "packages/app" , "playwright" , "test" , "e2e/benchmark.spec.ts" ] ,
5481 { cwd : root , maxBuffer : 10 * 1024 * 1024 } ,
5582 ) ;
56- const result = JSON . parse ( await readFile ( timings , "utf8" ) ) as Omit <
57- NativeTiming ,
58- "endToEndMs"
59- > ;
60- if ( index > 0 ) {
61- nativeRuns . push ( {
62- ...result ,
63- endToEndMs : result . totalMs ,
64- totalMs :
65- result . prepareMs +
66- result . loadMs +
67- result . inferenceMs +
68- result . finalizeMs ,
69- } ) ;
70- }
71- }
72- await writeFile (
73- resolve ( data , "native.json" ) ,
74- JSON . stringify ( { backend : "native" , runs : nativeRuns } , null , 2 ) ,
75- ) ;
83+ const webRuns = (
84+ JSON . parse ( await readFile ( resolve ( data , "web.json" ) , "utf8" ) ) as {
85+ runs : Timing [ ] ;
86+ }
87+ ) . runs ;
7688
77- await exec (
78- "pnpm" ,
79- [ "-C" , "packages/app" , "playwright" , "test" , "e2e/benchmark.spec.ts" ] ,
80- { cwd : root , maxBuffer : 10 * 1024 * 1024 } ,
81- ) ;
82- const webRuns = (
83- JSON . parse ( await readFile ( resolve ( data , "web.json" ) , "utf8" ) ) as {
84- runs : Timing [ ] ;
85- }
86- ) . runs ;
87-
88- const result = {
89- fixture : { durationSeconds : 30 , sampleRate : 44_100 , channels : 2 } ,
90- settings : { model : "htdemucs" , mode : "full" , shifts : 1 } ,
91- environment : {
92- platform : process . platform ,
93- arch : process . arch ,
94- logicalCpus : availableParallelism ( ) ,
95- nativeIntraThreads : 4 ,
96- } ,
97- native : summarize ( nativeRuns ) ,
98- web : summarize ( webRuns ) ,
99- } ;
100- await writeFile ( resolve ( data , "summary.json" ) , JSON . stringify ( result , null , 2 ) ) ;
101- console . table ( {
102- native : result . native . median ,
103- web : result . web . median ,
104- } ) ;
105- console . log ( `Results: ${ resolve ( data , "summary.json" ) } ` ) ;
89+ const result = {
90+ fixture : { durationSeconds : 30 , sampleRate : 44_100 , channels : 2 } ,
91+ settings : { model : "htdemucs" , mode : "full" , shifts : 1 } ,
92+ environment : {
93+ platform : process . platform ,
94+ arch : process . arch ,
95+ logicalCpus : availableParallelism ( ) ,
96+ nativeIntraThreads : 4 ,
97+ } ,
98+ native : summarize ( nativeRuns ) ,
99+ web : summarize ( webRuns ) ,
100+ } ;
101+ await writeFile ( resolve ( data , "summary.json" ) , JSON . stringify ( result , null , 2 ) ) ;
102+ console . table ( {
103+ native : result . native . median ,
104+ web : result . web . median ,
105+ } ) ;
106+ console . log ( `Results: ${ resolve ( data , "summary.json" ) } ` ) ;
107+ }
106108
107109function summarize ( runs : Timing [ ] ) {
108110 return {
@@ -123,3 +125,5 @@ function median(values: number[]) {
123125 ? ( sorted [ middle - 1 ] + sorted [ middle ] ) / 2
124126 : sorted [ middle ] ;
125127}
128+
129+ main ( ) ;
0 commit comments