@@ -26,57 +26,122 @@ import { TextField } from 'tns-core-modules/ui/text-field';
2626import { TextView } from 'tns-core-modules/ui/text-view' ;
2727import { TimePicker } from 'tns-core-modules/ui/time-picker' ;
2828import { View } from 'tns-core-modules/ui/core/view' ;
29- import { FormattedString , Span } from "tns-core-modules/text/formatted-string" ;
29+ import { FormattedString , Span } from 'tns-core-modules/text/formatted-string' ;
30+ import { _getProperties , _getStyleProperties } from 'tns-core-modules/ui/core/properties' ;
31+ declare var __startCPUProfiler ;
32+ declare var __stopCPUProfiler ;
3033
31- export function testAll ( layout : StackLayout ) : string {
34+ const count = 200 ;
35+ export function testSetup ( layout : StackLayout ) : string {
3236 setupSetters ( ) ;
33- const count = 100 ;
34- let result = '' ;
35- // result += test(layout, () => new FlexboxLayout(), count);
36- // result += test(layout, () => new ActionBar(), count);
37- // result += test(layout, () => new ActivityIndicator(), count);
38- // result += test(layout, () => new Border(), count);
39- result += test ( layout , ( ) => new Button ( ) , count ) ;
40- // result += test(layout, () => new ContentView(), count);
41- // result += test(layout, () => new DatePicker(), count);
42- // result += test(layout, () => new HtmlView(), count);
43- // result += test(layout, () => new Image(), count);
44- // result += test(layout, () => new Label(), count);
45- // result += test(layout, () => new AbsoluteLayout(), count);
46- // result += test(layout, () => new DockLayout(), count);
47- // result += test(layout, () => new GridLayout(), count);
48- // result += test(layout, () => new StackLayout(), count);
49- // result += test(layout, () => new WrapLayout(), count);
50- // result += test(layout, () => new ListPicker(), count);
51- // result += test(layout, () => new ListView(), count);
52- // result += test(layout, () => new Page(), count);
53- // result += test(layout, () => new Progress(), count);
54- // result += test(layout, () => new Repeater(), count);
55- // result += test(layout, () => new Switch(), count);
56- // result += test(layout, () => new TextField(), count);
57- // result += test(layout, () => new TextView(), count);
58-
59- // Throws
60- // result += test(layout, () => new TabView(), count);
61- // result += test(layout, () => new SegmentedBar(), count);
62- // result += test(layout, () => new TimePicker(), count);
63-
64- return result ;
37+ return '' ;
38+ }
39+
40+ export function testFlexboxLayout ( layout : StackLayout ) : string {
41+ return test ( layout , ( ) => new FlexboxLayout ( ) , count ) ;
42+ }
43+
44+ export function testDockLayout ( layout : StackLayout ) : string {
45+ return test ( layout , ( ) => new DockLayout ( ) , count ) ;
46+ }
47+
48+ export function testGridLayout ( layout : StackLayout ) : string {
49+ return test ( layout , ( ) => new GridLayout ( ) , count ) ;
50+ }
51+
52+ export function testStackLayout ( layout : StackLayout ) : string {
53+ return test ( layout , ( ) => new StackLayout ( ) , count ) ;
54+ }
55+
56+ export function testWrapLayout ( layout : StackLayout ) : string {
57+ return test ( layout , ( ) => new WrapLayout ( ) , count ) ;
58+ }
59+
60+ export function testAbsoluteLayout ( layout : StackLayout ) : string {
61+ return test ( layout , ( ) => new AbsoluteLayout ( ) , count ) ;
62+ }
63+
64+ export function testButton ( layout : StackLayout ) : string {
65+ return test ( layout , ( ) => new Button ( ) , count ) ;
66+ }
67+
68+ export function testActionBar ( layout : StackLayout ) : string {
69+ return test ( layout , ( ) => new ActionBar ( ) , count ) ;
70+ }
71+
72+ export function testActivityIndicator ( layout : StackLayout ) : string {
73+ return test ( layout , ( ) => new ActivityIndicator ( ) , count ) ;
74+ }
75+
76+ export function testBorder ( layout : StackLayout ) : string {
77+ return test ( layout , ( ) => new Border ( ) , count ) ;
78+ }
79+
80+ export function testContentView ( layout : StackLayout ) : string {
81+ return test ( layout , ( ) => new ContentView ( ) , count ) ;
82+ }
83+
84+ export function testDatePicker ( layout : StackLayout ) : string {
85+ return test ( layout , ( ) => new DatePicker ( ) , count ) ;
86+ }
87+
88+ export function testHtmlView ( layout : StackLayout ) : string {
89+ return test ( layout , ( ) => new HtmlView ( ) , count ) ;
90+ }
91+
92+ export function testImage ( layout : StackLayout ) : string {
93+ return test ( layout , ( ) => new Image ( ) , count ) ;
94+ }
95+
96+ export function testLabel ( layout : StackLayout ) : string {
97+ return test ( layout , ( ) => new Label ( ) , count ) ;
98+ }
99+
100+ export function testListPicker ( layout : StackLayout ) : string {
101+ return test ( layout , ( ) => new ListPicker ( ) , count ) ;
102+ }
103+
104+ export function testListView ( layout : StackLayout ) : string {
105+ return test ( layout , ( ) => new ListView ( ) , count ) ;
106+ }
107+
108+ export function testPage ( layout : StackLayout ) : string {
109+ return test ( layout , ( ) => new Page ( ) , count ) ;
110+ }
111+
112+ export function testProgress ( layout : StackLayout ) : string {
113+ return test ( layout , ( ) => new Progress ( ) , count ) ;
114+ }
115+
116+ export function testRepeater ( layout : StackLayout ) : string {
117+ return test ( layout , ( ) => new Repeater ( ) , count ) ;
118+ }
119+
120+ export function testSwitch ( layout : StackLayout ) : string {
121+ return test ( layout , ( ) => new Switch ( ) , count ) ;
122+ }
123+
124+ export function testTextField ( layout : StackLayout ) : string {
125+ return test ( layout , ( ) => new TextField ( ) , count ) ;
126+ }
127+
128+ export function testTextView ( layout : StackLayout ) : string {
129+ return test ( layout , ( ) => new TextView ( ) , count ) ;
65130}
66131
67132function test ( layout : StackLayout , createView : ( ) => View , count : number ) : string {
68133 const viewMap1 = new Map < string , any > ( ) ;
69134 const cssMap1 = new Map < string , any > ( ) ;
70-
135+
71136 viewMap1 . set ( 'isEnabled' , false ) ;
72- let result = execute ( layout , createView , count , viewMap1 , cssMap1 ) + ', ' ;
137+ let result = execute ( layout , createView , count , viewMap1 , cssMap1 )
73138
74139 viewMap1 . set ( 'text' , 'text' ) ;
75140 viewMap1 . set ( 'automationText' , "automationText" ) ;
76141 cssMap1 . set ( 'width' , 100 ) ;
77142 cssMap1 . set ( 'height' , 100 ) ;
78143 cssMap1 . set ( 'rotate' , '90' ) ;
79- result += execute ( layout , createView , count , viewMap1 , cssMap1 ) + ', ' ;
144+ result += execute ( layout , createView , count , viewMap1 , cssMap1 )
80145
81146 viewMap1 . set ( 'clipToBounds' , false ) ;
82147 viewMap1 . set ( 'left' , '20' ) ;
@@ -91,7 +156,7 @@ function test(layout: StackLayout, createView: () => View, count: number): strin
91156 cssMap1 . set ( 'horizontalAlignment' , 'center' ) ;
92157 cssMap1 . set ( 'verticalAlignment' , 'center' ) ;
93158
94- result += execute ( layout , createView , count , viewMap1 , cssMap1 ) + ', ' ;
159+ result += execute ( layout , createView , count , viewMap1 , cssMap1 )
95160
96161 viewMap1 . set ( 'row' , '1' ) ;
97162 viewMap1 . set ( 'rowSpan' , '2' ) ;
@@ -110,45 +175,79 @@ function test(layout: StackLayout, createView: () => View, count: number): strin
110175 cssMap1 . set ( 'backgroundColor' , 'red' ) ;
111176 cssMap1 . set ( 'backgroundImage' , '~/logo.png' ) ;
112177
113- result += execute ( layout , createView , count , viewMap1 , cssMap1 ) + ', ' ;
178+ result += execute ( layout , createView , count , viewMap1 , cssMap1 )
114179 result += execute ( layout , createView , count , setters , cssSetters ) ;
115180
116- return `${ createView ( ) . typeName } : ${ result } \n ` ;
181+ return `${ createView ( ) . typeName } : ${ result } ` ;
117182}
118183
184+ let b = false ;
119185function execute ( layout : StackLayout , createView : ( ) => View , count : number ,
120186 viewProps : Map < string , any > , cssProps : Map < string , any > ) : string {
121- const not = profile ( layout , createView , count , false , viewProps , cssProps ) ;
122- const recycled = profile ( layout , createView , count , true , viewProps , cssProps ) ;
123-
124- const improved = ( ( not - recycled ) / not ) * 100 ;
125- console . log ( `recycled time: ${ recycled } ` ) ;
126- console . log ( `not recycled time: ${ not } ` ) ;
127- const propCount = viewProps . size + cssProps . size ;
128- return `${ propCount } : ${ improved . toFixed ( 0 ) } %` ;
187+
188+ gc ( ) ;
189+ java . lang . System . gc ( ) ;
190+ gc ( ) ;
191+ java . lang . System . gc ( ) ;
192+ // b = !b;
193+ // let not: { time: number, count: number };
194+ let recycled : { time : number , count : number } ;
195+ // if (b) {
196+ // not = profile(layout, createView, count, false, viewProps, cssProps);
197+ // recycled = profile(layout, createView, count, true, viewProps, cssProps);
198+ // } else {
199+ recycled = profile ( layout , createView , count , true , viewProps , cssProps ) ;
200+ // not = profile(layout, createView, count, false, viewProps, cssProps);
201+ // }
202+
203+ // console.log(`recycled: ${recycled.time}`);
204+ // console.log(`not: ${not.time}`);
205+ // const improved = ((not.time - recycled.time) / not.time) * 100;
206+ const propCount = recycled . count ;
207+ return `\t${ recycled . time . toFixed ( 0 ) } ` ;
129208}
130209
210+ const props = _getProperties ( ) ;
211+ const styleProps = _getStyleProperties ( ) ;
212+
131213function profile ( layout : StackLayout , createView : ( ) => View , count : number , recycle : boolean ,
132- viewProps : Map < string , any > , cssProps : Map < string , any > ) : number {
214+ viewProps : Map < string , any > , cssProps : Map < string , any > ) : { time : number , count : number } {
133215
134216 const view = createView ( ) ;
135217 view . recycleNativeView = recycle ? 'always' : 'never' ;
136218 const style = view . style ;
137-
138- viewProps . forEach ( ( v , k ) => view [ k ] = v ) ;
139- cssProps . forEach ( ( v , k ) => style [ k ] = v ) ;
140-
141- gc ( ) ;
142- java . lang . System . gc ( ) ;
143- const start = time ( ) ;
144-
145- for ( let i = 0 ; i < count ; i ++ ) {
146- layout . addChild ( view ) ;
147- layout . removeChild ( view ) ;
219+ // DatePicker throws OOM
220+ const c = view . typeName === 'DatePicker' ? 1 : 5 ;
221+ let total = 0 ;
222+ let x = 0 ;
223+ for ( let i = 0 ; i < c ; i ++ ) {
224+ x = 0 ;
225+ viewProps . forEach ( ( v , k ) => {
226+ const p = props . find ( vp => ( < any > vp ) . name === k ) ;
227+ // if (p && view[p.setNative]) {
228+ view [ k ] = v ;
229+ x ++ ;
230+ // }
231+ } ) ;
232+
233+ cssProps . forEach ( ( v , k ) => {
234+ const p = styleProps . find ( vp => ( < any > vp ) . name === k ) ;
235+ // if (p && view[p.setNative]) {
236+ style [ k ] = v ;
237+ x ++ ;
238+ // }
239+ } ) ;
240+
241+ const start = time ( ) ;
242+ for ( let i = 0 ; i < count ; i ++ ) {
243+ layout . addChild ( view ) ;
244+ layout . removeChild ( view ) ;
245+ }
246+ const end = time ( ) - start ;
247+ total += end ;
148248 }
149249
150- const end = time ( ) - start ;
151- return end ;
250+ return { time : total / c , count : x } ;
152251}
153252
154253let setters : Map < string , any > ;
@@ -282,11 +381,11 @@ function setupSetters(): void {
282381 setters . set ( 'androidOffscreenTabLimit' , '2' ) ;
283382
284383 // text-base
285- const formattedText = new FormattedString ( ) ;
286- const span = new Span ( ) ;
287- span . text = 'span' ;
288- formattedText . spans . push ( span ) ;
289- setters . set ( 'formattedText' , formattedText ) ;
384+ // const formattedText = new FormattedString();
385+ // const span = new Span();
386+ // span.text = 'span';
387+ // formattedText.spans.push(span);
388+ // setters.set('formattedText', formattedText);
290389
291390 // text-base
292391 setters . set ( 'secure' , 'true' ) ;
0 commit comments