Advertisement
hbabayan

Grunt performance

Nov 22nd, 2013
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * Execute "grunt test-speed" in order to see duration for each case
  3.  */
  4. module.exports = function(grunt) {
  5.     require('load-grunt-tasks')(grunt);
  6.    
  7.     grunt['initConfig']({
  8.         pkg: grunt.file.readJSON('package.json'),  
  9.        
  10.         concurrent: {
  11.             target1: ['long1', 'long2']
  12.         }
  13.     });
  14.    
  15.    
  16.     grunt.registerTask('long1', 'Long task 1', function(){
  17.         var fs = require('fs');
  18.         for(var i=0; i<1000000; i++) {
  19.             fs.existsSync(i) && console.log('foo');
  20.         }
  21.         console.log('long task 1 finished');
  22.     });
  23.  
  24.     grunt.registerTask('long2', 'Long task 2', function(){
  25.         var fs = require('fs');
  26.         for(var i=0; i<1000000; i++) {
  27.             fs.existsSync(i) && console.log('foo');
  28.         }
  29.         console.log('long task 1 finished');
  30.     });
  31.  
  32.     grunt.registerTask('date', 'print date', function(){
  33.         console.log((new Date()));
  34.     });
  35.  
  36.     //Run long tasks one after other
  37.     grunt.registerTask('long', ['long1', 'long2']);
  38.  
  39.     //Run long tasks in parallel
  40.     grunt.registerTask('p-long', ['concurrent:target1']);
  41.  
  42.     //Measure speed in both cases
  43.     grunt.registerTask('test-speed', ['date', 'p-long', 'date', 'long', 'date']);
  44. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement