我如何比较(Jagged Arrays,Arrays,ArrayList)的性能?

时间:2022-02-06 06:27:21

Is there any performance counter? Or i really get result like that:

有没有性能指标?或者我真的得到这样的结果:

Jagged Arrays: 2000 ms
Arrays : 3000 ms
ArrayList : 4000 ms

锯齿状阵列:2000 ms阵列:300​​0 ms ArrayList:4000 ms


How can i code method to get performance result?

我如何编写方法来获得性能结果?

7 个解决方案

#1


The stopwatch class is useful for timing microbenchmarks:

秒表类对计时微基准测试非常有用:

http://msdn.microsoft.com/en-us/library/system.diagnostics.stopwatch.aspx

#2


Rico Mariani is your man. he makes the best performance staticstics for .net.

Rico Mariani是你的男人。他为.net制作了最佳性能静电。

so, to start how to do it, read his blog.

所以,要开始怎么做,请阅读他的博客。

How to test Array speed

如何测试阵列速度

results of these tests

这些测试的结果

basically, what you should mesure is the access of the items. not adding them.

基本上,你应该知道的是物品的访问权限。不添加它们。

#3


You can have a look at this question, it has some code, results and discussion

你可以看看这个问题,它有一些代码,结果和讨论

#4


Honestly, if you need a profiler to tell you it's working better, you probably don't need to worry about it. So, just compile your code three different ways -- jagged arrays, array lists, and array classic. If any of them consistently runs [job X] noticeably faster, you've got it. If you can't feel the improvement firsthand, you're probably just wasting your most valuable resource: developer time.

老实说,如果你需要一个分析器告诉你它工作得更好,你可能不需要担心它。因此,只需以三种不同的方式编译代码 - 锯齿状数组,数组列表和数组经典。如果他们中的任何一个一直运行[作业X]明显更快,你就得到了它。如果您无法直接感受到改进,那么您可能只是在浪费您最宝贵的资源:开发人员时间。

#5


Performance of different storage structures will vary depending on the operations you require to carry out on said structure.

不同存储结构的性能将根据您在所述结构上执行所需的操作而变化。

General tests might be
Sorting: Bubble, Merge
Searching: Sequential, Sequential (with unsorted data), Binary

一般测试可能是排序:冒泡,合并搜索:顺序,顺序(带有未排序的数据),二进制

Writing a function for testing these would involve filling up some arrays with an equal amount of random data and then performing the tests.

编写用于测试这些函数的函数将涉及用等量的随机数据填充一些数组,然后执行测试。

Producing time based metrics of performance is generally pretty simple with these types of algorithms.

使用这些类型的算法,生成基于时间的性能指标通常非常简单。

Depending on language, you can time how long it takes to compute with the use of timers or simply storing/outputting the timestamps of each iteration point you choose.

根据语言,您可以计算使用计时器计算所需的时间,或者只是存储/输出您选择的每个迭代点的时间戳。

#6


You can set some performance counter on application and then measure the performance..

您可以在应用程序上设置一些性能计数器,然后测量性能。

Here is the good link. http://www.codeproject.com/KB/dotnet/perfcounter.aspx

这是一个很好的链接。 http://www.codeproject.com/KB/dotnet/perfcounter.aspx

#7


create a class that contains 2 jagged array as follows

创建一个包含2个锯齿状数组的类,如下所示

0    0123     
01   012  
012  01  
0123 0  

and two constructors. Then create a class that inherits jagged class, that contains a two dimensional array and 2 methods:

和两个构造函数。然后创建一个继承锯齿状类的类,它包含一个二维数组和两个方法:

create_matrix method that creates the matrix from the two inherited jagged arrays as follows:

create_matrix方法,从两个继承的锯齿状数组创建矩阵,如下所示:

0 0 1 2 3
0 1 0 1 2
0 1 2 0 1
0 1 2 3 0

display method that displays the two jagged arrays and the resulted matrix.

显示两个锯齿状数组和结果矩阵的显示方法。

#1


The stopwatch class is useful for timing microbenchmarks:

秒表类对计时微基准测试非常有用:

http://msdn.microsoft.com/en-us/library/system.diagnostics.stopwatch.aspx

#2


Rico Mariani is your man. he makes the best performance staticstics for .net.

Rico Mariani是你的男人。他为.net制作了最佳性能静电。

so, to start how to do it, read his blog.

所以,要开始怎么做,请阅读他的博客。

How to test Array speed

如何测试阵列速度

results of these tests

这些测试的结果

basically, what you should mesure is the access of the items. not adding them.

基本上,你应该知道的是物品的访问权限。不添加它们。

#3


You can have a look at this question, it has some code, results and discussion

你可以看看这个问题,它有一些代码,结果和讨论

#4


Honestly, if you need a profiler to tell you it's working better, you probably don't need to worry about it. So, just compile your code three different ways -- jagged arrays, array lists, and array classic. If any of them consistently runs [job X] noticeably faster, you've got it. If you can't feel the improvement firsthand, you're probably just wasting your most valuable resource: developer time.

老实说,如果你需要一个分析器告诉你它工作得更好,你可能不需要担心它。因此,只需以三种不同的方式编译代码 - 锯齿状数组,数组列表和数组经典。如果他们中的任何一个一直运行[作业X]明显更快,你就得到了它。如果您无法直接感受到改进,那么您可能只是在浪费您最宝贵的资源:开发人员时间。

#5


Performance of different storage structures will vary depending on the operations you require to carry out on said structure.

不同存储结构的性能将根据您在所述结构上执行所需的操作而变化。

General tests might be
Sorting: Bubble, Merge
Searching: Sequential, Sequential (with unsorted data), Binary

一般测试可能是排序:冒泡,合并搜索:顺序,顺序(带有未排序的数据),二进制

Writing a function for testing these would involve filling up some arrays with an equal amount of random data and then performing the tests.

编写用于测试这些函数的函数将涉及用等量的随机数据填充一些数组,然后执行测试。

Producing time based metrics of performance is generally pretty simple with these types of algorithms.

使用这些类型的算法,生成基于时间的性能指标通常非常简单。

Depending on language, you can time how long it takes to compute with the use of timers or simply storing/outputting the timestamps of each iteration point you choose.

根据语言,您可以计算使用计时器计算所需的时间,或者只是存储/输出您选择的每个迭代点的时间戳。

#6


You can set some performance counter on application and then measure the performance..

您可以在应用程序上设置一些性能计数器,然后测量性能。

Here is the good link. http://www.codeproject.com/KB/dotnet/perfcounter.aspx

这是一个很好的链接。 http://www.codeproject.com/KB/dotnet/perfcounter.aspx

#7


create a class that contains 2 jagged array as follows

创建一个包含2个锯齿状数组的类,如下所示

0    0123     
01   012  
012  01  
0123 0  

and two constructors. Then create a class that inherits jagged class, that contains a two dimensional array and 2 methods:

和两个构造函数。然后创建一个继承锯齿状类的类,它包含一个二维数组和两个方法:

create_matrix method that creates the matrix from the two inherited jagged arrays as follows:

create_matrix方法,从两个继承的锯齿状数组创建矩阵,如下所示:

0 0 1 2 3
0 1 0 1 2
0 1 2 0 1
0 1 2 3 0

display method that displays the two jagged arrays and the resulted matrix.

显示两个锯齿状数组和结果矩阵的显示方法。