Last active
February 22, 2025 23:36
-
-
Save SirSerje/3eee3edd2fc844b8123fd693531472eb to your computer and use it in GitHub Desktop.
Performance test for vue vs react
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useEffect, useState } from "react"; | |
interface PerfTestProps { | |
pressureLevel: number; | |
} | |
export function PerfTest({ pressureLevel }: PerfTestProps) { | |
const [items, setItems] = useState<number[]>([]); | |
useEffect(() => { | |
const interval = setInterval(() => { | |
const newItems = Array.from({ length: pressureLevel * 10 }, () => Math.random()); | |
setItems(newItems); | |
}, 1000); | |
return () => clearInterval(interval); | |
}, [pressureLevel]); | |
return ( | |
<div> | |
<h3>Pressure Level: {pressureLevel}</h3> | |
{items.slice(0, 100).map((val, i) => ( | |
<div key={i}>{val}</div> | |
))} | |
</div> | |
); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<div> | |
<div v-for="(value, index) in items" :key="index"> | |
{{value}} | |
</div> | |
</div> | |
</template> | |
<script setup lang="ts"> | |
import { ref, onMounted, onUnmounted } from 'vue'; | |
const items = ref<number[]>([]); | |
const updateItems = () => { | |
items.value = Array.from({ length: 10000 }, () => Math.random()); | |
}; | |
let intervalId: number; | |
onMounted(() => { | |
updateItems(); | |
intervalId = window.setInterval(updateItems, 1000); | |
}); | |
onUnmounted(() => { | |
clearInterval(intervalId); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is there a reason for the slice in react and not one for vue?