| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @license | 
					
						
							|  |  |  |  * Copyright Google Inc. All Rights Reserved. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Use of this source code is governed by an MIT-style license that can be | 
					
						
							|  |  |  |  * found in the LICENSE file at https://angular.io/license
 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-06 16:11:20 -08:00
										 |  |  | import {defineComponent} from '../../src/render3/index'; | 
					
						
							| 
									
										
										
										
											2019-03-14 14:15:10 -07:00
										 |  |  | import {container, containerRefreshEnd, containerRefreshStart, elementEnd, elementStart, embeddedViewEnd, embeddedViewStart, text} from '../../src/render3/instructions/all'; | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  | import {RenderFlags} from '../../src/render3/interfaces/definition'; | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  | import {document, renderComponent} from './render_util'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | describe('iv perf test', () => { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const count = 100000; | 
					
						
							|  |  |  |   const noOfIterations = 10; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   describe('render', () => { | 
					
						
							|  |  |  |     for (let iteration = 0; iteration < noOfIterations; iteration++) { | 
					
						
							|  |  |  |       it(`${iteration}. create ${count} divs in DOM`, () => { | 
					
						
							|  |  |  |         const start = new Date().getTime(); | 
					
						
							|  |  |  |         const container = document.createElement('div'); | 
					
						
							|  |  |  |         for (let i = 0; i < count; i++) { | 
					
						
							|  |  |  |           const div = document.createElement('div'); | 
					
						
							|  |  |  |           div.appendChild(document.createTextNode('-')); | 
					
						
							|  |  |  |           container.appendChild(div); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         const end = new Date().getTime(); | 
					
						
							|  |  |  |         log(`${count} DIVs in DOM`, (end - start) / count); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it(`${iteration}. create ${count} divs in Render3`, () => { | 
					
						
							|  |  |  |         class Component { | 
					
						
							|  |  |  |           static ngComponentDef = defineComponent({ | 
					
						
							| 
									
										
										
										
											2018-01-22 15:27:21 -08:00
										 |  |  |             type: Component, | 
					
						
							| 
									
										
										
										
											2018-03-29 16:41:45 -07:00
										 |  |  |             selectors: [['div']], | 
					
						
							| 
									
										
										
										
											2018-08-16 18:53:21 -07:00
										 |  |  |             consts: 1, | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |             vars: 0, | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |             template: function Template(rf: RenderFlags, ctx: any) { | 
					
						
							|  |  |  |               if (rf & RenderFlags.Create) { | 
					
						
							| 
									
										
										
										
											2018-02-06 16:11:20 -08:00
										 |  |  |                 container(0); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |               } | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |               if (rf & RenderFlags.Update) { | 
					
						
							|  |  |  |                 containerRefreshStart(0); | 
					
						
							|  |  |  |                 { | 
					
						
							|  |  |  |                   for (let i = 0; i < count; i++) { | 
					
						
							| 
									
										
										
										
											2018-08-18 11:14:50 -07:00
										 |  |  |                     let rf0 = embeddedViewStart(0, 2, 0); | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |                     { | 
					
						
							|  |  |  |                       if (rf0 & RenderFlags.Create) { | 
					
						
							|  |  |  |                         elementStart(0, 'div'); | 
					
						
							|  |  |  |                         text(1, '-'); | 
					
						
							|  |  |  |                         elementEnd(); | 
					
						
							|  |  |  |                       } | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |                     } | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |                     embeddedViewEnd(); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |                   } | 
					
						
							|  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2018-04-10 20:57:09 -07:00
										 |  |  |                 containerRefreshEnd(); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |               } | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |             factory: () => new Component | 
					
						
							|  |  |  |           }); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         const start = new Date().getTime(); | 
					
						
							|  |  |  |         renderComponent(Component); | 
					
						
							|  |  |  |         const end = new Date().getTime(); | 
					
						
							|  |  |  |         log(`${count} DIVs in Render3`, (end - start) / count); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function log(text: string, duration: number) { | 
					
						
							|  |  |  |   // tslint:disable-next-line:no-console
 | 
					
						
							|  |  |  |   console.log(text, duration * 1000, 'ns'); | 
					
						
							|  |  |  | } |