Advertisement
Guest User

Untitled

a guest
Sep 27th, 2018
339
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 'use strict';
  2.  
  3. function provaSlice ( tmp, i, chunkSize ) {
  4.  
  5.     if ( tmp[i] === undefined ) {
  6.         return;
  7.     }
  8.     else {
  9.         let chunk = tmp.slice(i, chunkSize);
  10.         i += chunkSize;
  11.         //console.log(`tmp array length == ${tmp.length}\n`);
  12.         //console.log( `chunkSize is: ${chunkSize}\n i is ${i}\nArray chunk has length equal to ${chunk.length} }` );
  13.         provaSlice( tmp, i, chunkSize );
  14.     }
  15.  
  16. }
  17.  
  18. function provaForEach ( rubrica, chunkSize ){
  19.     let chunk=[];
  20.     let rubricaLength = rubrica.length;
  21.     rubrica.forEach( (contact, i) => {
  22.         chunk.push(contact);
  23.         if( chunk.length==chunkSize || rubricaLength-1==i ) {
  24.             //console.log('\n\n'+i+') REQUEST - chunk length '+ chunk.length +' is: '+JSON.stringify(chunk) );
  25.             chunk=[];
  26.         }
  27.     });
  28. }
  29.  
  30.  
  31.  
  32. let tmp = [
  33.         {
  34.           "id": 748,
  35.           "uuid": "a31be504-aa8c-4907-8723-d76fa5ffc7fd",
  36.           "fullname": "Aaron Lombardo",
  37.           "email": "aaron.lombardo_256@customer.biuti.it",
  38.           "phone": "+90 553 01745647",
  39.           "gravatar": "https://gravatar.com/avatar/a31be504-aa8c-4907-8723-d76fa5ffc7fd@biuti.com",
  40.           "photo_profile": "https://s3.amazonaws.com/uifaces/faces/twitter/rehatkathuria/128.jpg",
  41.           "fiscal_code": null,
  42.           "vat_code": null,
  43.           "iban_code": null,
  44.           "home_address": null,
  45.           "is_enabled": true,
  46.           "last_login_at": "2018-09-26T22:09:06.008Z",
  47.           "created_at": "2018-09-26T22:26:00.832Z",
  48.           "role": {
  49.             "id": 1,
  50.             "label": "Customer",
  51.             "description": null,
  52.             "icon": null,
  53.             "sort": 1
  54.           },
  55.           "status": {
  56.             "id": 1,
  57.             "label": "available",
  58.             "description": null,
  59.             "sort": 1
  60.           }
  61.         },
  62.         {
  63.           "id": 748,
  64.           "uuid": "a31be504-aa8c-4907-8723-d76fa5ffc7fd",
  65.           "fullname": "Aaron Lombardo",
  66.           "email": "aaron.lombardo_256@customer.biuti.it",
  67.           "phone": "+90 553 01745647",
  68.           "gravatar": "https://gravatar.com/avatar/a31be504-aa8c-4907-8723-d76fa5ffc7fd@biuti.com",
  69.           "photo_profile": "https://s3.amazonaws.com/uifaces/faces/twitter/rehatkathuria/128.jpg",
  70.           "fiscal_code": null,
  71.           "vat_code": null,
  72.           "iban_code": null,
  73.           "home_address": null,
  74.           "is_enabled": true,
  75.           "last_login_at": "2018-09-26T22:09:06.008Z",
  76.           "created_at": "2018-09-26T22:26:00.832Z",
  77.           "role": {
  78.             "id": 1,
  79.             "label": "Customer",
  80.             "description": null,
  81.             "icon": null,
  82.             "sort": 1
  83.           },
  84.           "status": {
  85.             "id": 1,
  86.             "label": "available",
  87.             "description": null,
  88.             "sort": 1
  89.           }
  90.         },
  91.         {
  92.           "id": 616,
  93.           "uuid": "b4a76925-96ca-4116-8324-4c61a5bf6530",
  94.           "fullname": "Abramo Cattaneo",
  95.           "email": "abramo.cattaneo_388@customer.biuti.it",
  96.           "phone": "+28 51 5137997",
  97.           "gravatar": "https://gravatar.com/avatar/b4a76925-96ca-4116-8324-4c61a5bf6530@biuti.com",
  98.           "photo_profile": "https://s3.amazonaws.com/uifaces/faces/twitter/linux29/128.jpg",
  99.           "fiscal_code": null,
  100.           "vat_code": null,
  101.           "iban_code": null,
  102.           "home_address": null,
  103.           "is_enabled": true,
  104.           "last_login_at": "2018-09-26T00:31:16.143Z",
  105.           "created_at": "2018-09-26T22:26:00.818Z",
  106.           "role": {
  107.             "id": 1,
  108.             "label": "Customer",
  109.             "description": null,
  110.             "icon": null,
  111.             "sort": 1
  112.           },
  113.           "status": {
  114.             "id": 3,
  115.             "label": "other...",
  116.             "description": null,
  117.             "sort": 3
  118.           }
  119.         },
  120.         {
  121.           "id": 24,
  122.           "uuid": "1e7008c1-dfba-4f30-bf6d-2fb7cec29917",
  123.           "fullname": "Abramo De Santis",
  124.           "email": "abramo.de santis_980@customer.biuti.it",
  125.           "phone": "+39 378 544 539",
  126.           "gravatar": "https://gravatar.com/avatar/1e7008c1-dfba-4f30-bf6d-2fb7cec29917@biuti.com",
  127.           "photo_profile": "https://s3.amazonaws.com/uifaces/faces/twitter/marrimo/128.jpg",
  128.           "fiscal_code": null,
  129.           "vat_code": null,
  130.           "iban_code": null,
  131.           "home_address": null,
  132.           "is_enabled": true,
  133.           "last_login_at": "2018-09-26T13:50:34.086Z",
  134.           "created_at": "2018-09-26T22:26:00.750Z",
  135.           "role": {
  136.             "id": 1,
  137.             "label": "Customer",
  138.             "description": null,
  139.             "icon": null,
  140.             "sort": 1
  141.           },
  142.           "status": {
  143.             "id": 3,
  144.             "label": "other...",
  145.             "description": null,
  146.             "sort": 3
  147.           }
  148.         },
  149.         {
  150.           "id": 353,
  151.           "uuid": "df33f3e0-0d88-4b55-80c3-53d6810e4bf3",
  152.           "fullname": "Abramo Donati",
  153.           "email": "abramo.donati_651@customer.biuti.it",
  154.           "phone": "+16 6770 8706281",
  155.           "gravatar": "https://gravatar.com/avatar/df33f3e0-0d88-4b55-80c3-53d6810e4bf3@biuti.com",
  156.           "photo_profile": "https://s3.amazonaws.com/uifaces/faces/twitter/alevizio/128.jpg",
  157.           "fiscal_code": null,
  158.           "vat_code": null,
  159.           "iban_code": null,
  160.           "home_address": null,
  161.           "is_enabled": true,
  162.           "last_login_at": "2018-09-26T15:25:20.783Z",
  163.           "created_at": "2018-09-26T22:26:00.781Z",
  164.           "role": {
  165.             "id": 1,
  166.             "label": "Customer",
  167.             "description": null,
  168.             "icon": null,
  169.             "sort": 1
  170.           },
  171.           "status": {
  172.             "id": 1,
  173.             "label": "available",
  174.             "description": null,
  175.             "sort": 1
  176.           }
  177.         },
  178.         {
  179.           "id": 390,
  180.           "uuid": "89bc27cd-9a90-48f0-ae81-74a6e417365a",
  181.           "fullname": "Abramo Gallo",
  182.           "email": "abramo.gallo_614@customer.biuti.it",
  183.           "phone": "+39 096 352 317",
  184.           "gravatar": "https://gravatar.com/avatar/89bc27cd-9a90-48f0-ae81-74a6e417365a@biuti.com",
  185.           "photo_profile": "https://s3.amazonaws.com/uifaces/faces/twitter/souperphly/128.jpg",
  186.           "fiscal_code": null,
  187.           "vat_code": null,
  188.           "iban_code": null,
  189.           "home_address": null,
  190.           "is_enabled": true,
  191.           "last_login_at": "2018-09-26T03:05:46.945Z",
  192.           "created_at": "2018-09-26T22:26:00.793Z",
  193.           "role": {
  194.             "id": 1,
  195.             "label": "Customer",
  196.             "description": null,
  197.             "icon": null,
  198.             "sort": 1
  199.           },
  200.           "status": {
  201.             "id": 2,
  202.             "label": "disabled",
  203.             "description": null,
  204.             "sort": 3
  205.           }
  206.         },
  207.         {
  208.           "id": 978,
  209.           "uuid": "1dc741e7-f2ba-4e07-a843-82844d2e2bf6",
  210.           "fullname": "Abramo Giuliani",
  211.           "email": "abramo.giuliani_26@customer.biuti.it",
  212.           "phone": "+46 40 4669299",
  213.           "gravatar": "https://gravatar.com/avatar/1dc741e7-f2ba-4e07-a843-82844d2e2bf6@biuti.com",
  214.           "photo_profile": "https://s3.amazonaws.com/uifaces/faces/twitter/itskawsar/128.jpg",
  215.           "fiscal_code": null,
  216.           "vat_code": null,
  217.           "iban_code": null,
  218.           "home_address": null,
  219.           "is_enabled": true,
  220.           "last_login_at": "2018-09-26T00:52:30.528Z",
  221.           "created_at": "2018-09-26T22:26:00.851Z",
  222.           "role": {
  223.             "id": 1,
  224.             "label": "Customer",
  225.             "description": null,
  226.             "icon": null,
  227.             "sort": 1
  228.           },
  229.           "status": {
  230.             "id": 2,
  231.             "label": "disabled",
  232.             "description": null,
  233.             "sort": 3
  234.           }
  235.         },
  236.         {
  237.           "id": 564,
  238.           "uuid": "9f265d4d-c3ff-41b2-b48b-a43f1f0b7c83",
  239.           "fullname": "Abramo Ross",
  240.           "email": "abramo.ross_440@customer.biuti.it",
  241.           "phone": "+05 2494 8799420",
  242.           "gravatar": "https://gravatar.com/avatar/9f265d4d-c3ff-41b2-b48b-a43f1f0b7c83@biuti.com",
  243.           "photo_profile": "https://s3.amazonaws.com/uifaces/faces/twitter/a_brixen/128.jpg",
  244.           "fiscal_code": null,
  245.           "vat_code": null,
  246.           "iban_code": null,
  247.           "home_address": null,
  248.           "is_enabled": true,
  249.           "last_login_at": "2018-09-26T12:59:25.201Z",
  250.           "created_at": "2018-09-26T22:26:00.809Z",
  251.           "role": {
  252.             "id": 1,
  253.             "label": "Customer",
  254.             "description": null,
  255.             "icon": null,
  256.             "sort": 1
  257.           },
  258.           "status": {
  259.             "id": 1,
  260.             "label": "available",
  261.             "description": null,
  262.             "sort": 1
  263.           }
  264.         },
  265.         {
  266.           "id": 45,
  267.           "uuid": "3dd06fe8-818d-4670-a4ba-25a3e863f352",
  268.           "fullname": "Abramo Sanna",
  269.           "email": "abramo.sanna_959@customer.biuti.it",
  270.           "phone": "+37 54 56555906",
  271.           "gravatar": "https://gravatar.com/avatar/3dd06fe8-818d-4670-a4ba-25a3e863f352@biuti.com",
  272.           "photo_profile": "https://s3.amazonaws.com/uifaces/faces/twitter/ajaxy_ru/128.jpg",
  273.           "fiscal_code": null,
  274.           "vat_code": null,
  275.           "iban_code": null,
  276.           "home_address": null,
  277.           "is_enabled": true,
  278.           "last_login_at": "2018-09-26T21:06:58.561Z",
  279.           "created_at": "2018-09-26T22:26:00.752Z",
  280.           "role": {
  281.             "id": 1,
  282.             "label": "Customer",
  283.             "description": null,
  284.             "icon": null,
  285.             "sort": 1
  286.           },
  287.           "status": {
  288.             "id": 2,
  289.             "label": "disabled",
  290.             "description": null,
  291.             "sort": 3
  292.           }
  293.         },
  294.         {
  295.           "id": 151,
  296.           "uuid": "b1b1ec33-ade6-42ca-b5a6-5f3a1f92edc1",
  297.           "fullname": "Adriano Colombo",
  298.           "email": "adriano.colombo_853@customer.biuti.it",
  299.           "phone": "+60 0997 3008322",
  300.           "gravatar": "https://gravatar.com/avatar/b1b1ec33-ade6-42ca-b5a6-5f3a1f92edc1@biuti.com",
  301.           "photo_profile": "https://s3.amazonaws.com/uifaces/faces/twitter/chris_frees/128.jpg",
  302.           "fiscal_code": null,
  303.           "vat_code": null,
  304.           "iban_code": null,
  305.           "home_address": null,
  306.           "is_enabled": true,
  307.           "last_login_at": "2018-09-26T18:07:28.902Z",
  308.           "created_at": "2018-09-26T22:26:00.762Z",
  309.           "role": {
  310.             "id": 1,
  311.             "label": "Customer",
  312.             "description": null,
  313.             "icon": null,
  314.             "sort": 1
  315.           },
  316.           "status": {
  317.             "id": 2,
  318.             "label": "disabled",
  319.             "description": null,
  320.             "sort": 3
  321.           }
  322.         },
  323.         {
  324.           "id": 395,
  325.           "uuid": "b0934d56-d33d-4e90-83eb-06ad8e0a1de2",
  326.           "fullname": "Adriano Coppola",
  327.           "email": "adriano.coppola_609@customer.biuti.it",
  328.           "phone": "351 014 644",
  329.           "gravatar": "https://gravatar.com/avatar/b0934d56-d33d-4e90-83eb-06ad8e0a1de2@biuti.com",
  330.           "photo_profile": "https://s3.amazonaws.com/uifaces/faces/twitter/ah_lice/128.jpg",
  331.           "fiscal_code": null,
  332.           "vat_code": null,
  333.           "iban_code": null,
  334.           "home_address": null,
  335.           "is_enabled": true,
  336.           "last_login_at": "2018-09-26T15:31:14.711Z",
  337.           "created_at": "2018-09-26T22:26:00.794Z",
  338.           "role": {
  339.             "id": 1,
  340.             "label": "Customer",
  341.             "description": null,
  342.             "icon": null,
  343.             "sort": 1
  344.           },
  345.           "status": {
  346.             "id": 2,
  347.             "label": "disabled",
  348.             "description": null,
  349.             "sort": 3
  350.           }
  351.         }
  352. ];
  353.  
  354. let i = 0, chunkSize = 3;
  355.  
  356. console.time('provaForEach');
  357. provaForEach ( tmp, chunkSize );
  358. console.timeEnd('provaForEach');
  359.  
  360. console.time('provaSlice');
  361. provaSlice( tmp, i, chunkSize );
  362. console.timeEnd('provaSlice');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement