Toto

Benchmark created on


Setup

const data = [
    {
        "id": "2292687284",
        "stream_id": "52339275021",
        "user_id": "92537604",
        "user_login": "grimkujow",
        "user_name": "Grimkujow",
        "title": "JE VAIS JOUER A LOL ET TU NE VAS RIEN FAIRE",
        "description": "",
        "created_at": "2024-11-03T14:39:26Z",
        "published_at": "2024-11-03T14:39:26Z",
        "url": "https://www.twitch.tv/videos/2292687284",
        "thumbnail_url": "https://static-cdn.jtvnw.net/cf_vods/d1m7jfoe9zdc1j/8b7a8654d251a96b9c0e_grimkujow_52339275021_1730644761//thumb/thumb0-%{width}x%{height}.jpg",
        "viewable": "public",
        "view_count": 31558,
        "language": "fr",
        "type": "archive",
        "duration": "6h1m0s",
        "muted_segments": null,
        "start_in_seconds": 56366,
        "duration_in_seconds": 21660,
        "end_in_seconds": 78026
    },
    {
        "id": "2292709262",
        "stream_id": "52339541101",
        "user_id": "28575692",
        "user_login": "mistermv",
        "user_name": "mistermv",
        "title": "FF7 REBIRTH : terminer le jeu avant le concert",
        "description": "",
        "created_at": "2024-11-03T15:11:56Z",
        "published_at": "2024-11-03T15:11:56Z",
        "url": "https://www.twitch.tv/videos/2292709262",
        "thumbnail_url": "https://static-cdn.jtvnw.net/cf_vods/d1m7jfoe9zdc1j/bca19da5b724128bfbf2_mistermv_52339541101_1730646711//thumb/thumb0-%{width}x%{height}.jpg",
        "viewable": "public",
        "view_count": 63921,
        "language": "fr",
        "type": "archive",
        "duration": "3h26m0s",
        "muted_segments": null,
        "start_in_seconds": 58316,
        "duration_in_seconds": 12360,
        "end_in_seconds": 70676
    },
    {
        "id": "2291888445",
        "stream_id": "43119918296",
        "user_id": "88301612",
        "user_login": "xari",
        "user_name": "Xari",
        "title": "SOIRÉE REPORTAGES",
        "description": "",
        "created_at": "2024-11-02T16:47:10Z",
        "published_at": "2024-11-02T16:47:10Z",
        "url": "https://www.twitch.tv/videos/2291888445",
        "thumbnail_url": "https://static-cdn.jtvnw.net/cf_vods/dgeft87wbj63p/30bcc54ded8029647632_xari_43119918296_1730566024//thumb/thumb0-%{width}x%{height}.jpg",
        "viewable": "public",
        "view_count": 57382,
        "language": "fr",
        "type": "archive",
        "duration": "6h49m30s",
        "muted_segments": null,
        "start_in_seconds": -22370,
        "duration_in_seconds": 24570,
        "end_in_seconds": 2200
    },
    {
        "id": "2292007711",
        "stream_id": "52333366893",
        "user_id": "92537604",
        "user_login": "grimkujow",
        "user_name": "Grimkujow",
        "title": "FAKER J'ARRIVE PRENDRE TA COURONNE",
        "description": "",
        "created_at": "2024-11-02T19:11:46Z",
        "published_at": "2024-11-02T19:11:46Z",
        "url": "https://www.twitch.tv/videos/2292007711",
        "thumbnail_url": "https://static-cdn.jtvnw.net/cf_vods/d1m7jfoe9zdc1j/759ff43ba687bd76bd17_grimkujow_52333366893_1730574701//thumb/thumb0-%{width}x%{height}.jpg",
        "viewable": "public",
        "view_count": 50561,
        "language": "fr",
        "type": "archive",
        "duration": "6h12m24s",
        "muted_segments": null,
        "start_in_seconds": -13694,
        "duration_in_seconds": 22344,
        "end_in_seconds": 8650
    },
    {
        "id": "2292932488",
        "stream_id": "43127342984",
        "user_id": "31289086",
        "user_login": "wankilstudio",
        "user_name": "WankilStudio",
        "title": "C'EST LE WANKIL SUNDAYYYYYY",
        "description": "",
        "created_at": "2024-11-03T19:57:33Z",
        "published_at": "2024-11-03T19:57:33Z",
        "url": "https://www.twitch.tv/videos/2292932488",
        "thumbnail_url": "https://static-cdn.jtvnw.net/cf_vods/dgeft87wbj63p/17e86f27b508ecba25a4_wankilstudio_43127342984_1730663845//thumb/thumb0-%{width}x%{height}.jpg",
        "viewable": "public",
        "view_count": 104849,
        "language": "fr",
        "type": "archive",
        "duration": "3h21m13s",
        "muted_segments": null,
        "start_in_seconds": 75453,
        "duration_in_seconds": 12073,
        "end_in_seconds": 87526
    },
    {
        "id": "2292932499",
        "stream_id": "43127342952",
        "user_id": "89872865",
        "user_login": "laink",
        "user_name": "Laink",
        "title": "C'EST LE WANKIL SUNDAYYYYYY",
        "description": "",
        "created_at": "2024-11-03T19:57:34Z",
        "published_at": "2024-11-03T19:57:34Z",
        "url": "https://www.twitch.tv/videos/2292932499",
        "thumbnail_url": "https://static-cdn.jtvnw.net/cf_vods/dgeft87wbj63p/fb33e1f1a6ee4cd19f46_laink_43127342952_1730663845//thumb/thumb0-%{width}x%{height}.jpg",
        "viewable": "public",
        "view_count": 30110,
        "language": "fr",
        "type": "archive",
        "duration": "3h21m13s",
        "muted_segments": null,
        "start_in_seconds": 75454,
        "duration_in_seconds": 12073,
        "end_in_seconds": 87527
    },
    {
        "id": "2292933350",
        "stream_id": "52342161565",
        "user_id": "89873316",
        "user_login": "terracid",
        "user_name": "Terracid",
        "title": "Votre dose de rigolade et de fun ^^",
        "description": "",
        "created_at": "2024-11-03T19:58:28Z",
        "published_at": "2024-11-03T19:58:28Z",
        "url": "https://www.twitch.tv/videos/2292933350",
        "thumbnail_url": "https://static-cdn.jtvnw.net/cf_vods/d1m7jfoe9zdc1j/412c4b865a167b7955ed_terracid_52342161565_1730663903//thumb/thumb0-%{width}x%{height}.jpg",
        "viewable": "public",
        "view_count": 45868,
        "language": "fr",
        "type": "archive",
        "duration": "3h20m0s",
        "muted_segments": null,
        "start_in_seconds": 75508,
        "duration_in_seconds": 12000,
        "end_in_seconds": 87508
    },
    {
        "id": "2292962825",
        "stream_id": "43127550168",
        "user_id": "27115917",
        "user_login": "kamet0",
        "user_name": "Kamet0",
        "title": "ON SE RETROUVE TRES VITE POUR UN PROCHAIN STREAM (!kcx) (!annonce)",
        "description": "",
        "created_at": "2024-11-03T20:33:17Z",
        "published_at": "2024-11-03T20:33:17Z",
        "url": "https://www.twitch.tv/videos/2292962825",
        "thumbnail_url": "https://static-cdn.jtvnw.net/cf_vods/dgeft87wbj63p/30a9537e39f6fbe44d87_kamet0_43127550168_1730665992//thumb/thumb0-%{width}x%{height}.jpg",
        "viewable": "public",
        "view_count": 292329,
        "language": "fr",
        "type": "archive",
        "duration": "3h28m50s",
        "muted_segments": null,
        "start_in_seconds": 77597,
        "duration_in_seconds": 12530,
        "end_in_seconds": 90127
    },
    {
        "id": "2293003150",
        "stream_id": "43127888648",
        "user_id": "28575692",
        "user_login": "mistermv",
        "user_name": "mistermv",
        "title": "FF7 REBIRTH : terminer le jeu avant le concert",
        "description": "",
        "created_at": "2024-11-03T21:25:55Z",
        "published_at": "2024-11-03T21:25:55Z",
        "url": "https://www.twitch.tv/videos/2293003150",
        "thumbnail_url": "https://static-cdn.jtvnw.net/cf_vods/dgeft87wbj63p/1acf89f6fcff32727f41_mistermv_43127888648_1730669150//thumb/thumb0-%{width}x%{height}.jpg",
        "viewable": "public",
        "view_count": 1462,
        "language": "fr",
        "type": "archive",
        "duration": "6h46m0s",
        "muted_segments": null,
        "start_in_seconds": 80755,
        "duration_in_seconds": 24360,
        "end_in_seconds": 105115
    },
    {
        "id": "2293012644",
        "stream_id": "43127969144",
        "user_id": "88301612",
        "user_login": "xari",
        "user_name": "Xari",
        "title": "XARI REACT",
        "description": "",
        "created_at": "2024-11-03T21:39:16Z",
        "published_at": "2024-11-03T21:39:16Z",
        "url": "https://www.twitch.tv/videos/2293012644",
        "thumbnail_url": "https://static-cdn.jtvnw.net/cf_vods/dgeft87wbj63p/97e8881d0074aa1b5f12_xari_43127969144_1730669950//thumb/thumb0-%{width}x%{height}.jpg",
        "viewable": "public",
        "view_count": 33919,
        "language": "fr",
        "type": "archive",
        "duration": "5h7m50s",
        "muted_segments": null,
        "start_in_seconds": 81556,
        "duration_in_seconds": 18470,
        "end_in_seconds": 100026
    }
]

const laConcu1 = (inputVideos) => {
    const isBeetween = (number, min, max) => {
        return number >= min && number < max;
    };
    let maxLineIndex = 0;
    const videos = [];
    for (let i = 0; i < inputVideos.length; i++) {
        const video = { ...inputVideos[i] };
        for (let j = 0; j < videos.length; j++) {
            const prevVideo = videos[j];
            if (prevVideo.lineIndex === video.lineIndex) {
                if (isBeetween(video.start_in_seconds, prevVideo.start_in_seconds, prevVideo.end_in_seconds)
                    || isBeetween(video.end_in_seconds, prevVideo.start_in_seconds, prevVideo.end_in_seconds)
                    || (video.start_in_seconds < prevVideo.start_in_seconds && video.end_in_seconds > prevVideo.end_in_seconds)) {
                    video.lineIndex = video.lineIndex || 0;
                    video.lineIndex++;
                    j = 0;
                    if (video.lineIndex > maxLineIndex) {
                        maxLineIndex = video.lineIndex;
                    }
                }
            }
        }
        videos.push(video);
    }
    return {
        videos,
        maxLineIndex: maxLineIndex + 1,
    };
};

const laConcu2 = (inputVideos) => {
    const events = [];
    for (let video of inputVideos) {
        const copyVideo = { ...video };
        events.push({ type: "start", time: video.start_in_seconds, video: copyVideo });
        events.push({ type: "end", time: video.end_in_seconds, video: copyVideo });
    }
    ;
    events.sort((a, b) => {
        if (a.time === b.time) {
            return a.type === "end" ? -1 : 1;
        }
        return a.time - b.time;
    });
    let currentLine = 0;
    let lineFree = [];
    let maxLine = 0;
    const videos = [];
    for (let event of events) {
        if (event.type === "start") {
            if (lineFree.length > 0) {
                const lineIndex = Math.min(...lineFree);
                event.video.lineIndex = lineIndex;
                videos.push(event.video);
                lineFree = lineFree.filter(value => value !== lineIndex);
            }
            else {
                event.video.lineIndex = currentLine;
                videos.push(event.video);
                currentLine++;
                if (currentLine > maxLine) {
                    maxLine = currentLine;
                }
            }
        }
        if (event.type === "end") {
            if (event.video.lineIndex == null) {
                throw new Error("Line index no set");
            }
            lineFree.push(event.video.lineIndex);
        }
    }
    return {
        videos,
        maxLineIndex: maxLine,
    };
};

const laConcu3 = (inputVideos) => {
    const events = [];
    for (let video of inputVideos) {
        const copyVideo = { ...video };
        events.push({ type: "start", time: video.start_in_seconds, video: copyVideo });
        events.push({ type: "end", time: video.end_in_seconds, video: copyVideo });
    }
    ;
    events.sort((a, b) => {
        if (a.time === b.time) {
            return a.type === "end" ? -1 : 1;
        }
        return a.time - b.time;
    });
    let currentLine = 0;
    let maxLine = 0;
    const videos = [];
    for (let event of events) {
        if (event.type === "start") {
            event.video.lineIndex = currentLine;
            videos.push(event.video);
            currentLine++;
            if (currentLine > maxLine) {
                maxLine = currentLine;
            }
        }
        if (event.type === "end") {
            currentLine--;
        }
    }
    return {
        videos,
        maxLineIndex: maxLine,
    };
};

Test runner

Ready to run.

Testing in
TestOps/sec
La Concu 1
laConcu1(data);
ready
La Concu 2
laConcu2(data);
ready
La Concu 3
laConcu3(data);
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.