@@ -55,7 +55,7 @@ export default class VisualizerContainer extends React.Component {
5555 if ( this . props . arr !== prevProps . arr ) {
5656 this . setState ( { array : this . props . arr } ) ;
5757 this . setState ( { type : this . props . type } ) ;
58- this . resetArray ( ) ;
58+ // this.resetArray();
5959 this . clearTimeouts ( ) ;
6060 this . setState ( ( state , props ) => ( { lastPos : - 1 } ) ) ;
6161 }
@@ -83,6 +83,10 @@ export default class VisualizerContainer extends React.Component {
8383 this . setState ( { play : this . state . play } ) ;
8484 console . log ( "executed animations " ) ;
8585 }
86+ if ( this . state . execTime != prevState . execTime ) {
87+ this . setState ( { execTime : this . state . execTime } ) ;
88+ console . log ( "executed execTime " ) ;
89+ }
8690 }
8791
8892 resetArray ( ) {
@@ -112,6 +116,7 @@ export default class VisualizerContainer extends React.Component {
112116 this . setState ( { play : ! this . state . play } ) ;
113117 this . state . timeoutIds . forEach ( ( timeoutId ) => clearTimeout ( timeoutId ) ) ;
114118 this . setState ( { timeoutIds : [ ] } ) ;
119+ // this.setState({ lastPos: -1 });
115120 } ;
116121 pause = ( opt ) => {
117122 this . setState ( { play : ! this . state . play } ) ;
@@ -165,8 +170,12 @@ export default class VisualizerContainer extends React.Component {
165170
166171 mergeSort ( a ) {
167172 let animations = [ ] ;
173+ //const start = performance.now();
168174 if ( this . state . animations . length == 0 ) {
175+ const start = performance . now ( ) ;
169176 animations = getMergeSortAnimations ( this . state . array ) ;
177+ const end = performance . now ( ) ;
178+ this . setState ( { execTime : ( end - start ) . toFixed ( 4 ) } ) ;
170179 }
171180 if ( animations . length != 0 ) this . setState ( { animations } ) ;
172181 const timeoutIds = [ ] ;
@@ -220,6 +229,7 @@ export default class VisualizerContainer extends React.Component {
220229 timeDelay * ANIMATION_SPEED_MS
221230 ) ;
222231 timeoutIds . push ( timeoutId ) ;
232+
223233 //this.updateArray();
224234 this . setState ( { timeoutIds } ) ;
225235 this . updateArray ( ) ;
@@ -228,7 +238,10 @@ export default class VisualizerContainer extends React.Component {
228238 quickSort ( a ) {
229239 let animations = [ ] ;
230240 if ( this . state . animations . length == 0 ) {
241+ const start = performance . now ( ) ;
231242 animations = getQuickSortAnimations ( this . state . array ) ;
243+ const end = performance . now ( ) ;
244+ this . setState ( { execTime : ( end - start ) . toFixed ( 4 ) } ) ;
232245 }
233246 if ( animations . length != 0 ) this . setState ( { animations } ) ;
234247 const timeoutIds = [ ] ;
@@ -307,7 +320,10 @@ export default class VisualizerContainer extends React.Component {
307320 ModifiedquickSort ( a ) {
308321 let animations = [ ] ;
309322 if ( this . state . animations . length == 0 ) {
323+ const start = performance . now ( ) ;
310324 animations = getOptimizedQuickSortAnimations ( this . state . array ) ;
325+ const end = performance . now ( ) ;
326+ this . setState ( { execTime : ( end - start ) . toFixed ( 4 ) } ) ;
311327 }
312328 if ( animations . length != 0 ) this . setState ( { animations } ) ;
313329 const timeoutIds = [ ] ;
@@ -439,7 +455,10 @@ export default class VisualizerContainer extends React.Component {
439455 insertionSort ( a ) {
440456 let animations = [ ] ;
441457 if ( this . state . animations . length == 0 ) {
458+ const start = performance . now ( ) ;
442459 animations = getInsertionSortAnimations ( this . state . array ) ;
460+ const end = performance . now ( ) ;
461+ this . setState ( { execTime : ( end - start ) . toFixed ( 4 ) } ) ;
443462 }
444463 const arrlength = this . state . array . length ;
445464 if ( animations . length != 0 ) this . setState ( { animations } ) ;
@@ -508,7 +527,10 @@ export default class VisualizerContainer extends React.Component {
508527 countSort ( a ) {
509528 let animations = [ ] ;
510529 if ( this . state . animations . length == 0 ) {
530+ const start = performance . now ( ) ;
511531 animations = getCountingSortAnimations ( this . state . array ) ;
532+ const end = performance . now ( ) ;
533+ this . setState ( { execTime : ( end - start ) . toFixed ( 4 ) } ) ;
512534 }
513535 const arrlength = this . state . array . length ;
514536 if ( animations . length != 0 ) this . setState ( { animations } ) ;
@@ -577,11 +599,15 @@ export default class VisualizerContainer extends React.Component {
577599 let firstNum = 40 ;
578600 let secondNum = 100 ;
579601 if ( this . state . animations . length == 0 ) {
602+ const start = performance . now ( ) ;
603+
580604 animations = getCountElementsAnimations (
581605 this . state . array ,
582606 firstNum ,
583607 secondNum
584608 ) ;
609+ const end = performance . now ( ) ;
610+ this . setState ( { execTime : ( end - start ) . toFixed ( 4 ) } ) ;
585611 }
586612 const arrlength = this . state . array . length ;
587613 if ( animations . length != 0 ) this . setState ( { animations } ) ;
@@ -662,7 +688,10 @@ export default class VisualizerContainer extends React.Component {
662688 radixSort ( a ) {
663689 let animations = [ ] ;
664690 if ( this . state . animations . length == 0 ) {
691+ const start = performance . now ( ) ;
665692 animations = getRadixSortAnimations ( this . state . array ) ;
693+ const end = performance . now ( ) ;
694+ this . setState ( { execTime : ( end - start ) . toFixed ( 4 ) } ) ;
666695 }
667696 const arrlength = this . state . array . length ;
668697 console . log ( "I am good" ) ;
@@ -748,7 +777,11 @@ export default class VisualizerContainer extends React.Component {
748777 heapSort ( a ) {
749778 let animations = [ ] ;
750779 if ( this . state . animations . length == 0 ) {
780+ const start = performance . now ( ) ;
781+
751782 animations = getHeapSortAnimations ( this . state . array ) ;
783+ const end = performance . now ( ) ;
784+ this . setState ( { execTime : ( end - start ) . toFixed ( 4 ) } ) ;
752785 }
753786 if ( animations . length != 0 ) this . setState ( { animations } ) ;
754787 const timeoutIds = [ ] ;
@@ -811,7 +844,11 @@ export default class VisualizerContainer extends React.Component {
811844 bubbleSort ( a ) {
812845 let animations = [ ] ;
813846 if ( this . state . animations . length == 0 ) {
847+ const start = performance . now ( ) ;
848+
814849 animations = getBubbleSortAnimations ( this . state . array ) ;
850+ const end = performance . now ( ) ;
851+ this . setState ( { execTime : ( end - start ) . toFixed ( 4 ) } ) ;
815852 }
816853 if ( animations . length != 0 ) this . setState ( { animations } ) ;
817854 const timeoutIds = [ ] ;
@@ -892,7 +929,10 @@ export default class VisualizerContainer extends React.Component {
892929 bucketSort ( a ) {
893930 let animations = [ ] ;
894931 if ( this . state . animations . length == 0 ) {
932+ const start = performance . now ( ) ;
895933 animations = getBucketSortAnimations ( this . state . array ) ;
934+ const end = performance . now ( ) ;
935+ this . setState ( { execTime : ( end - start ) . toFixed ( 4 ) } ) ;
896936 }
897937 const arrlength = this . state . array . length ;
898938 if ( animations . length != 0 ) this . setState ( { animations } ) ;
@@ -1024,7 +1064,7 @@ export default class VisualizerContainer extends React.Component {
10241064 onInput = { onInputhandler }
10251065 > </ input >
10261066 < span style = { { fontWeight : 700 } } >
1027- Execution time: { this . state . execTime } { " " }
1067+ Execution time: { this . state . execTime } ms
10281068 </ span >
10291069 </ div >
10301070 </ div >
0 commit comments