Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'use strict';
- function provaSlice ( tmp, i, chunkSize ) {
- if ( tmp[i] === undefined ) {
- return;
- }
- else {
- let chunk = tmp.slice(i, chunkSize);
- i += chunkSize;
- //console.log(`tmp array length == ${tmp.length}\n`);
- //console.log( `chunkSize is: ${chunkSize}\n i is ${i}\nArray chunk has length equal to ${chunk.length} }` );
- provaSlice( tmp, i, chunkSize );
- }
- }
- function provaForEach ( rubrica, chunkSize ){
- let chunk=[];
- let rubricaLength = rubrica.length;
- rubrica.forEach( (contact, i) => {
- chunk.push(contact);
- if( chunk.length==chunkSize || rubricaLength-1==i ) {
- //console.log('\n\n'+i+') REQUEST - chunk length '+ chunk.length +' is: '+JSON.stringify(chunk) );
- chunk=[];
- }
- });
- }
- let tmp = [
- {
- "id": 748,
- "uuid": "a31be504-aa8c-4907-8723-d76fa5ffc7fd",
- "fullname": "Aaron Lombardo",
- "email": "aaron.lombardo_256@customer.biuti.it",
- "phone": "+90 553 01745647",
- "gravatar": "https://gravatar.com/avatar/a31be504-aa8c-4907-8723-d76fa5ffc7fd@biuti.com",
- "photo_profile": "https://s3.amazonaws.com/uifaces/faces/twitter/rehatkathuria/128.jpg",
- "fiscal_code": null,
- "vat_code": null,
- "iban_code": null,
- "home_address": null,
- "is_enabled": true,
- "last_login_at": "2018-09-26T22:09:06.008Z",
- "created_at": "2018-09-26T22:26:00.832Z",
- "role": {
- "id": 1,
- "label": "Customer",
- "description": null,
- "icon": null,
- "sort": 1
- },
- "status": {
- "id": 1,
- "label": "available",
- "description": null,
- "sort": 1
- }
- },
- {
- "id": 748,
- "uuid": "a31be504-aa8c-4907-8723-d76fa5ffc7fd",
- "fullname": "Aaron Lombardo",
- "email": "aaron.lombardo_256@customer.biuti.it",
- "phone": "+90 553 01745647",
- "gravatar": "https://gravatar.com/avatar/a31be504-aa8c-4907-8723-d76fa5ffc7fd@biuti.com",
- "photo_profile": "https://s3.amazonaws.com/uifaces/faces/twitter/rehatkathuria/128.jpg",
- "fiscal_code": null,
- "vat_code": null,
- "iban_code": null,
- "home_address": null,
- "is_enabled": true,
- "last_login_at": "2018-09-26T22:09:06.008Z",
- "created_at": "2018-09-26T22:26:00.832Z",
- "role": {
- "id": 1,
- "label": "Customer",
- "description": null,
- "icon": null,
- "sort": 1
- },
- "status": {
- "id": 1,
- "label": "available",
- "description": null,
- "sort": 1
- }
- },
- {
- "id": 616,
- "uuid": "b4a76925-96ca-4116-8324-4c61a5bf6530",
- "fullname": "Abramo Cattaneo",
- "email": "abramo.cattaneo_388@customer.biuti.it",
- "phone": "+28 51 5137997",
- "gravatar": "https://gravatar.com/avatar/b4a76925-96ca-4116-8324-4c61a5bf6530@biuti.com",
- "photo_profile": "https://s3.amazonaws.com/uifaces/faces/twitter/linux29/128.jpg",
- "fiscal_code": null,
- "vat_code": null,
- "iban_code": null,
- "home_address": null,
- "is_enabled": true,
- "last_login_at": "2018-09-26T00:31:16.143Z",
- "created_at": "2018-09-26T22:26:00.818Z",
- "role": {
- "id": 1,
- "label": "Customer",
- "description": null,
- "icon": null,
- "sort": 1
- },
- "status": {
- "id": 3,
- "label": "other...",
- "description": null,
- "sort": 3
- }
- },
- {
- "id": 24,
- "uuid": "1e7008c1-dfba-4f30-bf6d-2fb7cec29917",
- "fullname": "Abramo De Santis",
- "email": "abramo.de santis_980@customer.biuti.it",
- "phone": "+39 378 544 539",
- "gravatar": "https://gravatar.com/avatar/1e7008c1-dfba-4f30-bf6d-2fb7cec29917@biuti.com",
- "photo_profile": "https://s3.amazonaws.com/uifaces/faces/twitter/marrimo/128.jpg",
- "fiscal_code": null,
- "vat_code": null,
- "iban_code": null,
- "home_address": null,
- "is_enabled": true,
- "last_login_at": "2018-09-26T13:50:34.086Z",
- "created_at": "2018-09-26T22:26:00.750Z",
- "role": {
- "id": 1,
- "label": "Customer",
- "description": null,
- "icon": null,
- "sort": 1
- },
- "status": {
- "id": 3,
- "label": "other...",
- "description": null,
- "sort": 3
- }
- },
- {
- "id": 353,
- "uuid": "df33f3e0-0d88-4b55-80c3-53d6810e4bf3",
- "fullname": "Abramo Donati",
- "email": "abramo.donati_651@customer.biuti.it",
- "phone": "+16 6770 8706281",
- "gravatar": "https://gravatar.com/avatar/df33f3e0-0d88-4b55-80c3-53d6810e4bf3@biuti.com",
- "photo_profile": "https://s3.amazonaws.com/uifaces/faces/twitter/alevizio/128.jpg",
- "fiscal_code": null,
- "vat_code": null,
- "iban_code": null,
- "home_address": null,
- "is_enabled": true,
- "last_login_at": "2018-09-26T15:25:20.783Z",
- "created_at": "2018-09-26T22:26:00.781Z",
- "role": {
- "id": 1,
- "label": "Customer",
- "description": null,
- "icon": null,
- "sort": 1
- },
- "status": {
- "id": 1,
- "label": "available",
- "description": null,
- "sort": 1
- }
- },
- {
- "id": 390,
- "uuid": "89bc27cd-9a90-48f0-ae81-74a6e417365a",
- "fullname": "Abramo Gallo",
- "email": "abramo.gallo_614@customer.biuti.it",
- "phone": "+39 096 352 317",
- "gravatar": "https://gravatar.com/avatar/89bc27cd-9a90-48f0-ae81-74a6e417365a@biuti.com",
- "photo_profile": "https://s3.amazonaws.com/uifaces/faces/twitter/souperphly/128.jpg",
- "fiscal_code": null,
- "vat_code": null,
- "iban_code": null,
- "home_address": null,
- "is_enabled": true,
- "last_login_at": "2018-09-26T03:05:46.945Z",
- "created_at": "2018-09-26T22:26:00.793Z",
- "role": {
- "id": 1,
- "label": "Customer",
- "description": null,
- "icon": null,
- "sort": 1
- },
- "status": {
- "id": 2,
- "label": "disabled",
- "description": null,
- "sort": 3
- }
- },
- {
- "id": 978,
- "uuid": "1dc741e7-f2ba-4e07-a843-82844d2e2bf6",
- "fullname": "Abramo Giuliani",
- "email": "abramo.giuliani_26@customer.biuti.it",
- "phone": "+46 40 4669299",
- "gravatar": "https://gravatar.com/avatar/1dc741e7-f2ba-4e07-a843-82844d2e2bf6@biuti.com",
- "photo_profile": "https://s3.amazonaws.com/uifaces/faces/twitter/itskawsar/128.jpg",
- "fiscal_code": null,
- "vat_code": null,
- "iban_code": null,
- "home_address": null,
- "is_enabled": true,
- "last_login_at": "2018-09-26T00:52:30.528Z",
- "created_at": "2018-09-26T22:26:00.851Z",
- "role": {
- "id": 1,
- "label": "Customer",
- "description": null,
- "icon": null,
- "sort": 1
- },
- "status": {
- "id": 2,
- "label": "disabled",
- "description": null,
- "sort": 3
- }
- },
- {
- "id": 564,
- "uuid": "9f265d4d-c3ff-41b2-b48b-a43f1f0b7c83",
- "fullname": "Abramo Ross",
- "email": "abramo.ross_440@customer.biuti.it",
- "phone": "+05 2494 8799420",
- "gravatar": "https://gravatar.com/avatar/9f265d4d-c3ff-41b2-b48b-a43f1f0b7c83@biuti.com",
- "photo_profile": "https://s3.amazonaws.com/uifaces/faces/twitter/a_brixen/128.jpg",
- "fiscal_code": null,
- "vat_code": null,
- "iban_code": null,
- "home_address": null,
- "is_enabled": true,
- "last_login_at": "2018-09-26T12:59:25.201Z",
- "created_at": "2018-09-26T22:26:00.809Z",
- "role": {
- "id": 1,
- "label": "Customer",
- "description": null,
- "icon": null,
- "sort": 1
- },
- "status": {
- "id": 1,
- "label": "available",
- "description": null,
- "sort": 1
- }
- },
- {
- "id": 45,
- "uuid": "3dd06fe8-818d-4670-a4ba-25a3e863f352",
- "fullname": "Abramo Sanna",
- "email": "abramo.sanna_959@customer.biuti.it",
- "phone": "+37 54 56555906",
- "gravatar": "https://gravatar.com/avatar/3dd06fe8-818d-4670-a4ba-25a3e863f352@biuti.com",
- "photo_profile": "https://s3.amazonaws.com/uifaces/faces/twitter/ajaxy_ru/128.jpg",
- "fiscal_code": null,
- "vat_code": null,
- "iban_code": null,
- "home_address": null,
- "is_enabled": true,
- "last_login_at": "2018-09-26T21:06:58.561Z",
- "created_at": "2018-09-26T22:26:00.752Z",
- "role": {
- "id": 1,
- "label": "Customer",
- "description": null,
- "icon": null,
- "sort": 1
- },
- "status": {
- "id": 2,
- "label": "disabled",
- "description": null,
- "sort": 3
- }
- },
- {
- "id": 151,
- "uuid": "b1b1ec33-ade6-42ca-b5a6-5f3a1f92edc1",
- "fullname": "Adriano Colombo",
- "email": "adriano.colombo_853@customer.biuti.it",
- "phone": "+60 0997 3008322",
- "gravatar": "https://gravatar.com/avatar/b1b1ec33-ade6-42ca-b5a6-5f3a1f92edc1@biuti.com",
- "photo_profile": "https://s3.amazonaws.com/uifaces/faces/twitter/chris_frees/128.jpg",
- "fiscal_code": null,
- "vat_code": null,
- "iban_code": null,
- "home_address": null,
- "is_enabled": true,
- "last_login_at": "2018-09-26T18:07:28.902Z",
- "created_at": "2018-09-26T22:26:00.762Z",
- "role": {
- "id": 1,
- "label": "Customer",
- "description": null,
- "icon": null,
- "sort": 1
- },
- "status": {
- "id": 2,
- "label": "disabled",
- "description": null,
- "sort": 3
- }
- },
- {
- "id": 395,
- "uuid": "b0934d56-d33d-4e90-83eb-06ad8e0a1de2",
- "fullname": "Adriano Coppola",
- "email": "adriano.coppola_609@customer.biuti.it",
- "phone": "351 014 644",
- "gravatar": "https://gravatar.com/avatar/b0934d56-d33d-4e90-83eb-06ad8e0a1de2@biuti.com",
- "photo_profile": "https://s3.amazonaws.com/uifaces/faces/twitter/ah_lice/128.jpg",
- "fiscal_code": null,
- "vat_code": null,
- "iban_code": null,
- "home_address": null,
- "is_enabled": true,
- "last_login_at": "2018-09-26T15:31:14.711Z",
- "created_at": "2018-09-26T22:26:00.794Z",
- "role": {
- "id": 1,
- "label": "Customer",
- "description": null,
- "icon": null,
- "sort": 1
- },
- "status": {
- "id": 2,
- "label": "disabled",
- "description": null,
- "sort": 3
- }
- }
- ];
- let i = 0, chunkSize = 3;
- console.time('provaForEach');
- provaForEach ( tmp, chunkSize );
- console.timeEnd('provaForEach');
- console.time('provaSlice');
- provaSlice( tmp, i, chunkSize );
- console.timeEnd('provaSlice');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement