diff.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /**
  2. * @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  4. */
  5. /* global console, setTimeout */
  6. import diff from '../../../src/diff';
  7. import getLongText from '../../_utils/longtext';
  8. // Tests
  9. setTimeout( () => {
  10. console.log( 'Testing... (t1 length - t2 length - avg time - times)' );
  11. execTime( getLongText( 300 ), getLongText( 700, false, true ) );
  12. execTime( getLongText( 350 ), getLongText( 700, false, true ) );
  13. execTime( getLongText( 400 ), getLongText( 700, false, true ) );
  14. execTime( getLongText( 450 ), getLongText( 700, false, true ) );
  15. execTime( getLongText( 300 ), getLongText( 800, false, true ) );
  16. execTime( getLongText( 350 ), getLongText( 800, false, true ) );
  17. execTime( getLongText( 400 ), getLongText( 800, false, true ) );
  18. execTime( getLongText( 450 ), getLongText( 800, false, true ) );
  19. execTime( getLongText( 300 ), getLongText( 900, false, true ) );
  20. execTime( getLongText( 350 ), getLongText( 900, false, true ) );
  21. execTime( getLongText( 400 ), getLongText( 900, false, true ) );
  22. execTime( getLongText( 450 ), getLongText( 900, false, true ) );
  23. execTime( getLongText( 300 ), getLongText( 1000, false, true ) );
  24. execTime( getLongText( 350 ), getLongText( 1000, false, true ) );
  25. execTime( getLongText( 400 ), getLongText( 1000, false, true ) );
  26. execTime( getLongText( 450 ), getLongText( 1000, false, true ) );
  27. execTime( getLongText( 300 ), getLongText( 1200, false, true ) );
  28. execTime( getLongText( 350 ), getLongText( 1200, false, true ) );
  29. execTime( getLongText( 400 ), getLongText( 1200, false, true ) );
  30. execTime( getLongText( 450 ), getLongText( 1200, false, true ) );
  31. execTime( getLongText( 300 ), getLongText( 1500, false, true ) );
  32. execTime( getLongText( 350 ), getLongText( 1500, false, true ) );
  33. execTime( getLongText( 400 ), getLongText( 1500, false, true ) );
  34. execTime( getLongText( 450 ), getLongText( 1500, false, true ) );
  35. }, 500 );
  36. // Helpers
  37. function execTime( text1, text2 ) {
  38. const times = [];
  39. for ( let i = 0; i < 15; i++ ) {
  40. const start = Number( new Date() );
  41. diff( text1, text2 );
  42. times.push( Number( new Date() ) - start );
  43. }
  44. console.log( 'l1: ' + text1.length, 'l2: ' + text2.length,
  45. 'avg: ' + Math.round( times.reduce( ( a, b ) => a + b, 0 ) / times.length ) + 'ms', times );
  46. }