简体   繁体   English

如何对 Blazor 组件进行性能测试?

[英]How can you performance test a Blazor component?

Is there a way to benchmark individual components performance?有没有办法对单个组件的性能进行基准测试?

For "normal code" you'd use something like benchmark .NET but I'm not sure that this is an accurate representation of a components performance when running inside an app, maybe it is for a server app and not for a WASM one?对于“普通代码”,您将使用诸如基准 .NET 之类的东西,但我不确定这是在应用程序中运行时组件性能的准确表示,也许它是用于服务器应用程序而不是 WASM 应用程序?

I'd like to find a way to test performance of the base components in our library to avoid regressions and make optimisations as needed.我想找到一种方法来测试我们库中基本组件的性能,以避免回归并根据需要进行优化。

Has anyone done anything like this or able to point me in the right direction?有没有人做过这样的事情或能够指出我正确的方向?

About two years ago, I bought a used PC for ten dollars.大约两年前,我花了十美元买了一台二手电脑。 It is very slow, and sometimes it takes 5 minutes to run a Blazor Server App.它非常慢,有时运行一个 Blazor 服务器应用程序需要 5 分钟。

One day I saw a bootstrap's carousel... I think it was Blazorise carousel component.有一天,我看到了一个引导程序的轮播……我认为它是 Blazorise 轮播组件。 I tested it, and then decided to built a model of my own, based on what I see.我对其进行了测试,然后根据我所见,决定构建我自己的 model。 In the course of developing my carousel I've realized this, thanks to the slowness of my PC: Never create unnecessary components;在开发我的轮播的过程中,由于我的电脑很慢,我意识到了这一点:永远不要创建不必要的组件; or rather, use RenderFragments instead of components.或者更确切地说,使用 RenderFragments 而不是组件。 I am not aware of any tools to do what you want, but I am perfectly aware that components are expensive and make your app slow, and that one must be careful with designing them.我不知道有什么工具可以做你想做的事,但我完全知道组件很昂贵并且会使你的应用程序变慢,并且必须小心设计它们。 Yes, it's very tempting to use components, but other factors should be taken into consideration.是的,使用组件很有诱惑力,但应该考虑其他因素。

Anyhow, I ended up creating my carousel with only two components.无论如何,我最终只用两个组件创建了我的轮播。 Item slides do not have a component of their own.项目幻灯片没有自己的组件。 When I defined an Item slide as a component, I could see how it is filled with an image with slow motion (remember my slow PC).当我将项目幻灯片定义为组件时,我可以看到它是如何用慢动作图像填充的(记住我的慢速 PC)。 But when I moved the relevant code from a component to a plain HTML div element, the Item slide appeared already filled with an image... Even in my slow PC, human eye could not discern the transition from empty Item slide to one filled with an image.但是当我将相关代码从一个组件移动到一个普通的 HTML div元素时,项目幻灯片似乎已经充满了图像......即使在我的慢速 PC 中,人眼也无法辨别从空项目幻灯片到充满一个图像。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 Http 和计时器对 blazor 组件进行单元测试? - How can I unit test a blazor component with Http and a Timer? 如何创建 blazor 组件? - How can i create a blazor component? 如何在 bunit Blazor 组件单元测试中注入 NavigationManager - How to inject NavigationManager in bunit Blazor component unit test 如何使用 bUnit 或任何其他组件在 Blazor 组件上测试与 JS 的交互? - How to test interaction with JS on a Blazor component using bUnit or any other? 如何在 Blazor 中呈现定义为对象的组件? - How can I render a component in Blazor that is defined as object? 如何在 Blazor(子)组件中引用“@typeparam TModel”字段? - How can I reference a "@typeparam TModel" field in the Blazor (sub)-component? Blazor 父组件能否知道它里面有多少子组件? - Can a Blazor Parent Component Know How Many Child Components Are Inside It? 如何在 Blazor 的 onkeypress 方法中读取输入的当前值? - How can you read the current value of an input in an onkeypress method in Blazor? 如何为 blazor 集成 Radzen 列表框组件? - How can i integrate Radzen listbox component for blazor? 如何从 Blazor 服务器中的页面处理(销毁)组件? - How can I dispose (destroy) a component from a page in Blazor Server?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM