Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const searchEntries = [];
- const excludeTags = [];
- const terms = [];
- const validOffers = [];
- const validRestaurantsIds = [];
- const opts = {
- showBadge: true,
- showPrice: true,
- showPriceDiscount: true,
- showPriceFull: true,
- showPriceMode: true,
- showPriceSize: true,
- showPriceMetric: true,
- showTitle: true,
- showDescription: true,
- showLogo: true,
- showRestaurantId: true,
- showImages: true
- };
- const generateOfferBadgeSimple = (opts, offer) => {
- let badge = '';
- if (opts.showBadge) {
- badge = offer.badge;
- }
- return badge;
- };
- console.log('Populating data...');
- for (let i = 0; i < 1000; i++) {
- const se = {
- isOpen: () => true,
- getOffers: () => [
- {
- id: i,
- title: 'title',
- description: 'description',
- tag: 'tag',
- metric_description: 'metric_description',
- size_info: 'size_info',
- full_price: 'full_price',
- mode: 'mode',
- price: 'price',
- logo: 'logo',
- restaurant_id: i,
- badge: 'badge',
- images: {
- menu: null,
- menu_bh: null
- }
- }
- ],
- getId: () => i
- };
- searchEntries.push(se);
- excludeTags.push('tag' + i);
- terms.push('title' + i);
- }
- console.time('Array map vanilla');
- searchEntries.forEach((se, sid) => {
- if (!se.isOpen()) {return;}
- const offers = se.getOffers([], excludeTags);
- offers.forEach((o) => {
- terms.forEach((t) => {
- if (o.titleSlug?.includes(t) || o.descriptionSlug?.includes(t)) {
- const offer = {
- id:o.id,
- title:o.title,
- description:o.description,
- tag:o.tag,
- metric_description:o.metric_description,
- size_info:o.size_info,
- full_price:o.full_price,
- mode:o.mode,
- price:o.price,
- logo:o.logo,
- restaurant_id: se.getId(),
- badge: generateOfferBadgeSimple(opts, o),
- images: {
- menu: null,
- menu_bh: null
- }
- };
- validOffers.push(offer);
- validRestaurantsIds.push(sid);
- }
- });
- });
- });
- console.timeEnd('Array map vanilla');
- // reset
- validOffers.length = 0;
- validRestaurantsIds.length = 0;
- console.time('Array map vanilla2');
- for (let sid = 0; sid < searchEntries.length; sid++) {
- const se = searchEntries[sid];
- if (!se.isOpen()) {
- continue;
- }
- const offers = se.getOffers([], excludeTags);
- for (let i = 0; i < offers.length; i++) {
- const o = offers[i];
- for (let j = 0; j < terms.length; j++) {
- const t = terms[j];
- if (o.titleSlug?.includes(t) || o.descriptionSlug?.includes(t)) {
- const offer = {
- id: o.id,
- title: o.title,
- description: o.description,
- tag: o.tag,
- metric_description: o.metric_description,
- size_info: o.size_info,
- full_price: o.full_price,
- mode: o.mode,
- price: o.price,
- logo: o.logo,
- restaurant_id: se.getId(),
- badge: generateOfferBadgeSimple(opts, o),
- images: {
- menu: null,
- menu_bh: null
- }
- };
- validOffers.push(offer);
- validRestaurantsIds.push(sid);
- }
- }
- }
- }
- console.timeEnd('Array map vanilla2');
Advertisement
Add Comment
Please, Sign In to add comment