Skip to content

Instantly share code, notes, and snippets.

@SirSerje
Last active February 22, 2025 23:36
Show Gist options
  • Save SirSerje/3eee3edd2fc844b8123fd693531472eb to your computer and use it in GitHub Desktop.
Save SirSerje/3eee3edd2fc844b8123fd693531472eb to your computer and use it in GitHub Desktop.
Performance test for vue vs react
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>
);
}
<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>
@PeterRincker
Copy link

Is there a reason for the slice in react and not one for vue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment