ASP.NET MVC路由的性能

时间:2021-12-29 04:52:43

Does anyone know, is routing processing time valuable in a comparison with the total request time? Will there be a large performance difference between an application with 20 and 100 (probably more) routings? Will be grateful for a link with the routings mechanism description.

有谁知道,与总请求时间相比,路由处理时间是否有价值?具有20和100(可能更多)路由的应用程序之间是否存在较大的性能差异?将感谢与路线机制描述的链接。

2 个解决方案

#1


2  

Take a look here. Please note that this is an old answer from 2008, but I would guess it still holds true. In particular note the bit about using named routes.

看看这里。请注意,这是2008年的一个老答案,但我猜它仍然适用。特别注意关于使用命名路由的一点。

In other words, if you know which route you will be using, then you can jump straight to the correct route with code like this: RedirectToRoute("routeName", viewData);and it won't waste time trawling through routes until it finds the correct one. This may seem a bit cumbersome, but it's better than hardcoding the routes as, if you change the way of generating your routes, this code will still work, whereas a hard coded route would break.

换句话说,如果你知道你将使用哪条路线,那么你可以直接跳到正确的路线,代码如下:RedirectToRoute(“routeName”,viewData);它不会浪费时间在路线上拖网,直到它找到正确的。这可能看起来有点麻烦,但它比硬编码路由更好,如果你改变生成路由的方式,这段代码仍然可以工作,而硬编码路由会破坏。

#2


1  

I would venture to say no, the time is insignificant compared to the overall processing time of the request in most scenarios.

我冒昧地说不,在大多数情况下,与请求的整体处理时间相比,时间是微不足道的。

There are a lot of variables that might be worth considering if you are going to benchmark this. For example, how simple/complex are those routes? Do they have constrains with regex on them? et cetera.

如果要对此进行基准测试,可能需要考虑很多变量。例如,这些路线有多简单/复杂?他们对正则表达式有约束吗?等等。

#1


2  

Take a look here. Please note that this is an old answer from 2008, but I would guess it still holds true. In particular note the bit about using named routes.

看看这里。请注意,这是2008年的一个老答案,但我猜它仍然适用。特别注意关于使用命名路由的一点。

In other words, if you know which route you will be using, then you can jump straight to the correct route with code like this: RedirectToRoute("routeName", viewData);and it won't waste time trawling through routes until it finds the correct one. This may seem a bit cumbersome, but it's better than hardcoding the routes as, if you change the way of generating your routes, this code will still work, whereas a hard coded route would break.

换句话说,如果你知道你将使用哪条路线,那么你可以直接跳到正确的路线,代码如下:RedirectToRoute(“routeName”,viewData);它不会浪费时间在路线上拖网,直到它找到正确的。这可能看起来有点麻烦,但它比硬编码路由更好,如果你改变生成路由的方式,这段代码仍然可以工作,而硬编码路由会破坏。

#2


1  

I would venture to say no, the time is insignificant compared to the overall processing time of the request in most scenarios.

我冒昧地说不,在大多数情况下,与请求的整体处理时间相比,时间是微不足道的。

There are a lot of variables that might be worth considering if you are going to benchmark this. For example, how simple/complex are those routes? Do they have constrains with regex on them? et cetera.

如果要对此进行基准测试,可能需要考虑很多变量。例如,这些路线有多简单/复杂?他们对正则表达式有约束吗?等等。