Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Array.flat vs [].concat(...array) / DayJS vs Date Native
(version: 11)
Comparing performance of:
Flat() / w DayJS vs [].concat(...arr) / w DayJS vs DayJS, Native Date, Concat both
Created:
3 years ago
by:
Registered User
Jump to the latest result
HTML Preparation code:
<script src="https://cdn.jsdelivr.net/npm/dayjs@1/dayjs.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/dayjs@1/plugin/utc.js"></script> <script src="https://cdn.jsdelivr.net/npm/dayjs@1/plugin/timezone.js"></script> <script>dayjs.extend(window.dayjs_plugin_utc);dayjs.extend(window.dayjs_plugin_timezone);</script>
Script Preparation code:
data = { "pages": [ [{ "id": "379668210364061232", "state": 0, "user": { "id": "379668207432242734", "nickname": "냥냥하는애옹이", "stove": { "nickname": "냥냥하는애옹이", "server": 8, "job": 64 }, "public_flags": 0 }, "server": 8, "continent": "슈샤이어", "zone": "서리감옥 고원", "card": "시안 카드", "rapport": 0, "extra": null, "created_at": "2022-11-10T10:51:11", "updated_at": null, "heart_count": 0, "is_hearted": null }, { "id": "379667979874472930", "state": 0, "user": { "id": "362919909501573783", "nickname": "나는야케찹될거양", "stove": { "nickname": "나는야케찹될거양", "server": 8, "job": 12 }, "public_flags": 0 }, "server": 8, "continent": "페이튼", "zone": "칼라자 마을", "card": "굴딩 카드", "rapport": 0, "extra": null, "created_at": "2022-11-10T10:50:17", "updated_at": null, "heart_count": 0, "is_hearted": null }, { "id": "379667051863741391", "state": 0, "user": { "id": "358630353151332380", "nickname": "moalu", "stove": { "nickname": "moalu", "server": 8, "job": 72 }, "public_flags": 0 }, "server": 8, "continent": "아르테미스", "zone": "로그힐", "card": "레온하트 네리아 카드", "rapport": 0, "extra": null, "created_at": "2022-11-10T10:46:35", "updated_at": null, "heart_count": 0, "is_hearted": null }, { "id": "379667030468597256", "state": 0, "user": { "id": "362919909501573783", "nickname": "나는야케찹될거양", "stove": { "nickname": "나는야케찹될거양", "server": 8, "job": 12 }, "public_flags": 0 }, "server": 8, "continent": "욘", "zone": "기약의 땅", "card": "위대한 성 네리아 카드", "rapport": 0, "extra": null, "created_at": "2022-11-10T10:46:30", "updated_at": null, "heart_count": 0, "is_hearted": null }, { "id": "379667009446745602", "state": 0, "user": { "id": "362089635775650865", "nickname": "내목표는돈많은백수임", "stove": { "nickname": "내목표는돈많은백수임", "server": 7, "job": 13 }, "public_flags": 0 }, "server": 7, "continent": "페이튼", "zone": "칼라자 마을", "card": "굴딩 카드", "rapport": 0, "extra": null, "created_at": "2022-11-10T10:46:25", "updated_at": null, "heart_count": 0, "is_hearted": null }, { "id": "379666043993461684", "state": 0, "user": { "id": "362089635775650865", "nickname": "내목표는돈많은백수임", "stove": { "nickname": "내목표는돈많은백수임", "server": 7, "job": 13 }, "public_flags": 0 }, "server": 7, "continent": "애니츠", "zone": "소리의 숲", "card": "수령도사 카드", "rapport": 1, "extra": null, "created_at": "2022-11-10T10:42:35", "updated_at": null, "heart_count": 1, "is_hearted": null }, { "id": "379665336867362244", "state": 0, "user": { "id": "369123748009349894", "nickname": "오늘은폭염", "stove": { "nickname": "오늘은폭염", "server": 8, "job": 82 }, "public_flags": 0 }, "server": 8, "continent": "애니츠", "zone": "거울 계곡", "card": "월향도사 카드", "rapport": 0, "extra": null, "created_at": "2022-11-10T10:39:46", "updated_at": null, "heart_count": 0, "is_hearted": null }, { "id": "379665264482063232", "state": 0, "user": { "id": "379014991027771361", "nickname": "금벽산수화", "stove": { "nickname": "금벽산수화", "server": 8, "job": 81 }, "public_flags": 0 }, "server": 8, "continent": "루테란 동부 (모리스)", "zone": "해무리 언덕", "card": "푸름 전사 브리뉴 카드", "rapport": 0, "extra": null, "created_at": "2022-11-10T10:39:29", "updated_at": null, "heart_count": 0, "is_hearted": null }, { "id": "379665178050040703", "state": 0, "user": { "id": "369123748009349894", "nickname": "오늘은폭염", "stove": { "nickname": "오늘은폭염", "server": 8, "job": 82 }, "public_flags": 0 }, "server": 8, "continent": "엘가시아", "zone": "필레니소스 산", "card": "별자리 큰뱀 카드", "rapport": 0, "extra": null, "created_at": "2022-11-10T10:39:09", "updated_at": null, "heart_count": 0, "is_hearted": null }, { "id": "379665116179862398", "state": 0, "user": { "id": "374462283084076414", "nickname": "츄르는레오꺼야", "stove": { "nickname": "츄르는레오꺼야", "server": 7, "job": 62 }, "public_flags": 0 }, "server": 7, "continent": "루테란 동부 (모리스)", "zone": "배꽃나무 자생지", "card": "천둥날개 카드", "rapport": 0, "extra": null, "created_at": "2022-11-10T10:38:54", "updated_at": null, "heart_count": 0, "is_hearted": null }], [{ "id": "379665094675666368", "state": 0, "user": { "id": "373377384579210088", "nickname": "유리아냐", "stove": { "nickname": "유리아냐", "server": 8, "job": 34 }, "public_flags": 0 }, "server": 8, "continent": "베른 남부", "zone": "칸다리아 영지", "card": "루기네 카드", "rapport": 0, "extra": null, "created_at": "2022-11-10T10:38:49", "updated_at": null, "heart_count": 0, "is_hearted": null }, { "id": "379665088690394557", "state": 0, "user": { "id": "357829211798507750", "nickname": "KULtB", "stove": { "nickname": "KULtB", "server": 2, "job": 61 }, "public_flags": 2 }, "server": 2, "continent": "욘", "zone": "검은모루 작업장", "card": "위대한 성 네리아 카드", "rapport": 0, "extra": null, "created_at": "2022-11-10T10:38:47", "updated_at": null, "heart_count": 0, "is_hearted": null }, { "id": "379664670501507946", "state": 0, "user": { "id": "374462283084076414", "nickname": "츄르는레오꺼야", "stove": { "nickname": "츄르는레오꺼야", "server": 7, "job": 62 }, "public_flags": 0 }, "server": 7, "continent": "베른 북부", "zone": "발란카르 산맥", "card": "기드온 카드", "rapport": 0, "extra": null, "created_at": "2022-11-10T10:37:08", "updated_at": null, "heart_count": 0, "is_hearted": null }, { "id": "379664513311577503", "state": 0, "user": { "id": "357964985248388290", "nickname": "구은소", "stove": { "nickname": "구은소", "server": 4, "job": 81 }, "public_flags": 2 }, "server": 4, "continent": "슈샤이어", "zone": "칼날바람 언덕", "card": "자베른 카드", "rapport": 0, "extra": null, "created_at": "2022-11-10T10:36:30", "updated_at": null, "heart_count": 1, "is_hearted": null }, { "id": "379664497834595742", "state": 0, "user": { "id": "375739617594448917", "nickname": "무흥이", "stove": { "nickname": "무흥이", "server": 8, "job": 31 }, "public_flags": 0 }, "server": 8, "continent": "베른 북부", "zone": "크로나 항구", "card": "페일린 카드", "rapport": 0, "extra": null, "created_at": "2022-11-10T10:36:26", "updated_at": null, "heart_count": 0, "is_hearted": null }, { "id": "379664441257629085", "state": 0, "user": { "id": "365217648809745230", "nickname": "우르프유미", "stove": { "nickname": "우르프유미", "server": 8, "job": 82 }, "public_flags": 0 }, "server": 8, "continent": "유디아", "zone": "오즈혼 구릉지", "card": "모리나 카드", "rapport": 0, "extra": null, "created_at": "2022-11-10T10:36:13", "updated_at": null, "heart_count": 0, "is_hearted": null }, { "id": "379664406386185057", "state": 0, "user": { "id": "357798918903435617", "nickname": "루크세온", "stove": { "nickname": "루크세온", "server": 5, "job": 44 }, "public_flags": 2 }, "server": 5, "continent": "베른 북부", "zone": "페스나르 고원", "card": "페일린 카드", "rapport": 0, "extra": null, "created_at": "2022-11-10T10:36:05", "updated_at": null, "heart_count": 1, "is_hearted": null }, { "id": "379664390745625440", "state": 0, "user": { "id": "374462283084076414", "nickname": "츄르는레오꺼야", "stove": { "nickname": "츄르는레오꺼야", "server": 7, "job": 62 }, "public_flags": 0 }, "server": 7, "continent": "슈샤이어", "zone": "얼음나비 절벽", "card": "진 매드닉 카드", "rapport": 0, "extra": null, "created_at": "2022-11-10T10:36:01", "updated_at": null, "heart_count": 0, "is_hearted": null }, { "id": "379664329865303413", "state": 0, "user": { "id": "357829211798507750", "nickname": "KULtB", "stove": { "nickname": "KULtB", "server": 2, "job": 61 }, "public_flags": 2 }, "server": 2, "continent": "슈샤이어", "zone": "칼날바람 언덕", "card": "자베른 카드", "rapport": 0, "extra": null, "created_at": "2022-11-10T10:35:46", "updated_at": null, "heart_count": 0, "is_hearted": null }, { "id": "379664302140953437", "state": 0, "user": { "id": "358177466738676050", "nickname": "플라나스", "stove": { "nickname": "플라나스", "server": 3, "job": 73 }, "public_flags": 2 }, "server": 3, "continent": "루테란 동부 (모리스)", "zone": "디오리카 평원", "card": "모르페오 카드", "rapport": 0, "extra": null, "created_at": "2022-11-10T10:35:40", "updated_at": null, "heart_count": 1, "is_hearted": null }], [{ "id": "379664248047015283", "state": 0, "user": { "id": "358177466738676050", "nickname": "플라나스", "stove": { "nickname": "플라나스", "server": 3, "job": 73 }, "public_flags": 2 }, "server": 3, "continent": "유디아", "zone": "오즈혼 구릉지", "card": "자이언트 웜 카드", "rapport": 0, "extra": null, "created_at": "2022-11-10T10:35:27", "updated_at": null, "heart_count": 1, "is_hearted": null }, { "id": "379664188827636568", "state": 0, "user": { "id": "357964985248388290", "nickname": "구은소", "stove": { "nickname": "구은소", "server": 4, "job": 81 }, "public_flags": 2 }, "server": 4, "continent": "아르테미스", "zone": "로그힐", "card": "레온하트 네리아 카드", "rapport": 0, "extra": null, "created_at": "2022-11-10T10:35:13", "updated_at": null, "heart_count": 1, "is_hearted": null }, { "id": "379664175833683314", "state": 0, "user": { "id": "379664173287740784", "nickname": "케이루아", "stove": { "nickname": "케이루아", "server": 3, "job": 73 }, "public_flags": 0 }, "server": 3, "continent": "엘가시아", "zone": "필레니소스 산", "card": "다이나웨일 카드", "rapport": 0, "extra": null, "created_at": "2022-11-10T10:35:10", "updated_at": null, "heart_count": 2, "is_hearted": null }, { "id": "379664158217606511", "state": 0, "user": { "id": "358177466738676050", "nickname": "플라나스", "stove": { "nickname": "플라나스", "server": 3, "job": 73 }, "public_flags": 2 }, "server": 3, "continent": "아르테미스", "zone": "로그힐", "card": "시이라 카드", "rapport": 0, "extra": null, "created_at": "2022-11-10T10:35:05", "updated_at": null, "heart_count": 1, "is_hearted": null }, { "id": "379664131546027374", "state": 0, "user": { "id": "357798918903435617", "nickname": "루크세온", "stove": { "nickname": "루크세온", "server": 5, "job": 44 }, "public_flags": 2 }, "server": 5, "continent": "베른 남부", "zone": "벨리온 유적지", "card": "사트라 카드", "rapport": 0, "extra": null, "created_at": "2022-11-10T10:34:59", "updated_at": null, "heart_count": 1, "is_hearted": null }, { "id": "379664089674290005", "state": 0, "user": { "id": "357964985248388290", "nickname": "구은소", "stove": { "nickname": "구은소", "server": 4, "job": 81 }, "public_flags": 2 }, "server": 4, "continent": "루테란 동부 (모리스)", "zone": "배꽃나무 자생지", "card": "모르페오 카드", "rapport": 0, "extra": null, "created_at": "2022-11-10T10:34:49", "updated_at": null, "heart_count": 1, "is_hearted": null }, { "id": "379664066102302051", "state": 0, "user": { "id": "357798918903435617", "nickname": "루크세온", "stove": { "nickname": "루크세온", "server": 5, "job": 44 }, "public_flags": 2 }, "server": 5, "continent": "루테란 동부 (모리스)", "zone": "디오리카 평원", "card": "푸름 전사 브리뉴 카드", "rapport": 0, "extra": null, "created_at": "2022-11-10T10:34:43", "updated_at": null, "heart_count": 1, "is_hearted": null }, { "id": "379664065334743891", "state": 0, "user": { "id": "357829211798507750", "nickname": "KULtB", "stove": { "nickname": "KULtB", "server": 2, "job": 61 }, "public_flags": 2 }, "server": 2, "continent": "루테란 동부 (모리스)", "zone": "디오리카 평원", "card": "모르페오 카드", "rapport": 0, "extra": null, "created_at": "2022-11-10T10:34:43", "updated_at": null, "heart_count": 1, "is_hearted": null }, { "id": "379664052462425442", "state": 0, "user": { "id": "364790256396015145", "nickname": "낭만창술사카카", "stove": { "nickname": "낭만창술사카카", "server": 4, "job": 34 }, "public_flags": 0 }, "server": 4, "continent": "유디아", "zone": "살란드 구릉지", "card": "자이언트 웜 카드", "rapport": 0, "extra": null, "created_at": "2022-11-10T10:34:40", "updated_at": null, "heart_count": 1, "is_hearted": null }, { "id": "379663957163643725", "state": 0, "user": { "id": "374462283084076414", "nickname": "츄르는레오꺼야", "stove": { "nickname": "츄르는레오꺼야", "server": 7, "job": 62 }, "public_flags": 0 }, "server": 7, "continent": "베른 남부", "zone": "칸다리아 영지", "card": "베른 젠로드 카드", "rapport": 0, "extra": null, "created_at": "2022-11-10T10:34:17", "updated_at": null, "heart_count": 0, "is_hearted": null }] ], "pageParams": [] } DEFAULT_TIMEZONE = "Asia/Seoul"
Tests:
Flat() / w DayJS
if (!data?.pages.length) return [] const newestReport = data.pages[0][0] const oldestReport = data.pages[data.pages.length - 1][data.pages[data.pages.length - 1].length - 1] const newestTimespan = dayjs(newestReport?.created_at).set('minute', 0).set('second', 0) const oldestTimespan = dayjs(oldestReport?.created_at).set('minute', 0).set('second', 0) const diff = newestTimespan.diff(oldestTimespan, 'hour') < 0 ? oldestTimespan.diff(newestTimespan, 'hour') : newestTimespan.diff(oldestTimespan, 'hour') const partitions = new Array(diff + 1).fill([-1, []]).map((a, i) => ([ dayjs.tz(newestReport?.created_at, 'utc').tz(DEFAULT_TIMEZONE).subtract(i + 1, 'hour'), a[1] ])) for (const report of data.pages.flat()) { const timespan = dayjs(report?.created_at).set('minute', 0).set('second', 0) const index = newestTimespan.diff(timespan, 'hour') // eslint-disable-next-line security/detect-object-injection partitions[index] = [ // eslint-disable-next-line security/detect-object-injection partitions[index]?.[0], // eslint-disable-next-line security/detect-object-injection [...(partitions[index]?.[1] ?? []), report] ] } partitions.map(reports => ([ reports[0], reports[1].filter((report, i, a) => a.findIndex(r => r.id === report.id) === i) ]))
[].concat(...arr) / w DayJS
if (!data?.pages.length) return [] const newestReport = data.pages[0][0] const oldestReport = data.pages[data.pages.length - 1][data.pages[data.pages.length - 1].length - 1] const newestTimespan = dayjs(newestReport?.created_at).set('minute', 0).set('second', 0) const oldestTimespan = dayjs(oldestReport?.created_at).set('minute', 0).set('second', 0) const diff = newestTimespan.diff(oldestTimespan, 'hour') < 0 ? oldestTimespan.diff(newestTimespan, 'hour') : newestTimespan.diff(oldestTimespan, 'hour') const partitions = new Array(diff + 1).fill([-1, []]).map((a, i) => ([ dayjs.tz(newestReport?.created_at, 'utc').tz(DEFAULT_TIMEZONE).subtract(i + 1, 'hour'), a[1] ])) for (const report of [].concat(...data.pages)) { const timespan = dayjs(report?.created_at).set('minute', 0).set('second', 0) const index = newestTimespan.diff(timespan, 'hour') // eslint-disable-next-line security/detect-object-injection partitions[index] = [ // eslint-disable-next-line security/detect-object-injection partitions[index]?.[0], // eslint-disable-next-line security/detect-object-injection [...(partitions[index]?.[1] ?? []), report] ] } partitions.map(reports => ([ reports[0], reports[1].filter((report, i, a) => a.findIndex(r => r.id === report.id) === i) ]))
DayJS, Native Date, Concat both
if (!data?.pages.length) return [] const newestReport = data.pages[0][0] const oldestReport = data.pages[data.pages.length - 1][data.pages[data.pages.length - 1].length - 1] const newestTimespan = new Date(newestReport?.created_at).setMinutes(0).setSeconds(0) const oldestTimespan = new Date(oldestReport?.created_at).setMinutes(0).setSeconds(0) const diffTime = Math.abs(oldestTimespan.getTime() - newestTimespan.getTime()) const diff = Math.ceil(diffTime / (1000 * 60 * 60)) const pivot = dayjs.tz(newestReport?.created_at, 'utc').tz(DEFAULT_TIMEZONE) const partitions = new Array(diff + 1).fill([-1, []]).map((a, i) => ([ pivot.subtract(i + 1, 'hour'), a[1] ])) for (const report of [].concat(...data.pages)) { const timespan = new Date(report?.created_at); timespan["__proto__"].setMinutes(0) timespan["__proto__"].setSeconds(0) const indexTime = Math.abs(newestTimespan.getTime() - timespan.getTime()) const index = Math.ceil(indexTime / (1000 * 60 * 60)) // eslint-disable-next-line security/detect-object-injection partitions[index] = [ // eslint-disable-next-line security/detect-object-injection partitions[index]?.[0], // eslint-disable-next-line security/detect-object-injection [...(partitions[index]?.[1] ?? []), report] ] } partitions.map(reports => ([ reports[0], reports[1].filter((report, i, a) => a.findIndex(r => r.id === report.id) === i) ]))
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Flat() / w DayJS
[].concat(...arr) / w DayJS
DayJS, Native Date, Concat both
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'll try to decipher the benchmarking report. Based on the provided data, I can see that there are two test cases: **Test Case 1:** `Array.prototype.concat()` with both `arr` and `DayJS` ```javascript function test1(arr) { return arr.concat(...arr); } ``` **Test Case 2:** `Flat()` (not explicitly shown in the report, but inferred from the benchmark results) ```javascript function test2() { const flat = []; for (const item of arr) { flat.push(item); } return flat; } ``` The benchmark results show two browsers running these tests: 1. **Chrome 107**: Both `Array.prototype.concat()` and `Flat()` produce similar execution rates, with the former being slightly faster. 2. **Unknown Browser**: The unknown browser's performance is not explicitly shown in the report. Here are some observations: * Both test cases have a high number of executions per second (e.g., 5211212.0 for `Array.prototype.concat()` and 230064.9375 for `Flat()`). * The execution rates are close, suggesting that both methods are optimized or implemented similarly. * It's unclear what the specific input data is, but it appears to be an array with multiple elements. Some possible conclusions: 1. **Both methods are optimized**: Both `Array.prototype.concat()` and `Flat()` seem to have efficient implementations that take advantage of the underlying array data structure. 2. **Performance parity**: The benchmark results suggest that both methods produce similar execution rates, which is good news for developers who need to choose between these two methods. However, I'd like more context or information about the specific input data and how it affects performance. Without this, it's difficult to draw more definitive conclusions.
Related benchmarks:
dsdsdsdsdsdsds
find in object array vs find in string array vs includes string array
[MH-4355][1000]: lodash / es6 filter perf
ISO 8601 parsing
Comments
Confirm delete:
Do you really want to delete benchmark?