1- import fs from "fs" ;
21import path , { dirname } from "path" ;
3- import { createDiff } from "../../src/services/createDiff.js" ;
42import { InputModels } from "../../src/interfaces/inputmodels.js" ;
53import { fileURLToPath } from "url" ;
6- import { convertAllXML , getFile } from "./utils.js" ;
4+ import { convertAllXML , writeJson } from "./utils.js" ;
5+ import { resolveAllRefs2_bunde , resolveAllRefs_Sol1 } from "../../src/utils/refHandler.js" ;
6+ import { JSONValue } from "../../src/utils/jsonHelper.js" ;
7+ import * as comparissonMergingService from "../../src/services/comparisonMerging.service.js" ;
8+
79
810const __filename = fileURLToPath ( import . meta. url ) ;
911const __dirname = dirname ( __filename ) ;
@@ -19,14 +21,17 @@ enum Side {
1921 ORIGINAL = "original" ,
2022}
2123
24+ const selectedSize = Size . SMALL ;
25+ const selectedSide = Side . ORIGINAL ;
26+
2227const xmlFolderPath = path . join (
2328 __dirname ,
24- `../data/EMFCompare_Models/model_size_${ Size . LARGE } /${ Side . ORIGINAL } ` ,
29+ `../data/EMFCompare_Models/model_size_${ selectedSize } /${ selectedSide } ` ,
2530) ;
2631
2732const jsonFolderPath = path . join (
2833 __dirname ,
29- `../data/${ Size . LARGE } /${ Side . ORIGINAL } ` ,
34+ `../data/${ selectedSize } /${ selectedSide } ` ,
3035) ;
3136
3237function measure < T > ( name : string , fn : ( ) => T ) : T {
@@ -36,23 +41,48 @@ function measure<T>(name: string, fn: () => T): T {
3641 return result ;
3742}
3843
39- function runPerformanceTest ( size : string ) {
44+ function runPerformanceTest ( size : Size ) {
4045 const fullPath = path . join ( __dirname , `../data/${ size } ` ) ;
4146 const modelFileName = "model.json" ;
4247
43- const inputModels : InputModels = {
44- left : getFile ( `${ fullPath } /original` , modelFileName ) ,
45- right : getFile ( `${ fullPath } /A` , modelFileName ) ,
46- } ;
48+ console . time ( "resolveRefs" ) ;
49+ Promise . all ( [
50+ resolveAllRefs2_bunde (
51+ `${ fullPath } /${ Side . ORIGINAL } ` ,
52+ `${ fullPath } /${ Side . ORIGINAL } /${ modelFileName } ` ,
53+ ) ,
54+ resolveAllRefs2_bunde (
55+ `${ fullPath } /${ Side . MODIFIED } ` ,
56+ `${ fullPath } /${ Side . MODIFIED } /${ modelFileName } ` ,
57+ ) ,
58+ ] )
59+ . then ( ( res ) => {
60+ console . timeEnd ( "resolveRefs" ) ;
61+
62+ const inputModels : InputModels = {
63+ left : res [ 0 ] as JSONValue ,
64+ right : res [ 1 ] as JSONValue ,
65+ } ;
4766
48- const diffmodel = measure ( "Small Model" , ( ) => {
49- const result = createDiff ( inputModels ) ;
50- return result ;
51- } ) ;
67+ writeJson ( fullPath , JSON . stringify ( inputModels . left , null , 2 ) , 'original_ref' ) ;
68+ writeJson ( fullPath , JSON . stringify ( inputModels . right , null , 2 ) , 'modified_ref' ) ;
5269
53- console . log ( diffmodel ) ;
70+ const diffmodel = measure ( `${ size } MODEL - Diff` , ( ) => {
71+ const result = comparissonMergingService . createDiff ( inputModels ) ;
72+ return result ;
73+ } ) ;
74+
75+ // console.log(diffmodel.differencesL, null, 2)
76+ console . log ( diffmodel . differencesL . length ) ;
77+ console . log ( diffmodel . differencesR . length ) ;
78+ } )
79+ . catch ( ( err ) => console . log ( err . stack ) ) ;
5480}
5581
56- convertAllXML ( xmlFolderPath , jsonFolderPath ) ;
82+ const args = process . argv . slice ( 2 ) ;
5783
58- // runPerformanceTest('small');
84+ if ( args . length > 0 && args [ 0 ] === "convert" ) {
85+ convertAllXML ( xmlFolderPath , jsonFolderPath ) ;
86+ } else {
87+ runPerformanceTest ( selectedSize ) ;
88+ }
0 commit comments