- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
编辑:在第二篇文章中查看下面更好的基准测试!!!
我在(Win8.1、Linux、BSD 和 OSX)上使用 .NET 4.5 与 Mono 3.2.x 进行了一些性能测试。
注意:这些测试是使用 Mono x86 或 .NET x86 arch 编译的。他们没有在 Virtual Box 中运行。测试计算机使用 native 运行的“Win8/Linux/BSD”进行三重启动,而 Mac 使用“OSX/Win7”进行双重启动。另请注意,“WIN32”编译器指令仅在 Win8/Win7 上用于“TimeBeginPeriod”,以在 Windows 中强制准确的秒表精度。 Linux/BSD/OSX 不需要这个,但 windows 需要。
这里是测试代码:
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
using numf = System.Single;
using numi = System.Int32;
#if WIN32
using System.Runtime.InteropServices;
#endif
namespace Benchmarks
{
struct Vector4
{
public numf X, Y, Z, W;
public static Vector4 operator+(Vector4 p1, Vector4 p2)
{
p1.X += p2.X;
p1.Y += p2.Y;
p1.Z += p2.Z;
p1.W += p2.W;
return p1;
}
public static Vector4 operator-(Vector4 p1, Vector4 p2)
{
p1.X -= p2.X;
p1.Y -= p2.Y;
p1.Z -= p2.Z;
p1.W -= p2.W;
return p1;
}
public static Vector4 operator*(Vector4 p1, Vector4 p2)
{
p1.X *= p2.X;
p1.Y *= p2.Y;
p1.Z *= p2.Z;
p1.W *= p2.W;
return p1;
}
public static Vector4 operator/(Vector4 p1, Vector4 p2)
{
p1.X /= p2.X;
p1.Y /= p2.Y;
p1.Z /= p2.Z;
p1.W /= p2.W;
return p1;
}
public override string ToString()
{
return string.Format("{0}, {1}, {2}, {3}", X, Y, Z, W);
}
}
class Program
{
#if WIN32
[StructLayout(LayoutKind.Sequential)]
public struct TimeCaps
{
public uint wPeriodMin;
public uint wPeriodMax;
}
private static TimeCaps caps;
[DllImport("winmm.dll", EntryPoint="timeGetDevCaps", SetLastError=true)]
public static extern uint TimeGetDevCaps(ref TimeCaps timeCaps, uint sizeTimeCaps);
[DllImport("winmm.dll", EntryPoint="timeBeginPeriod", SetLastError=true)]
public static extern uint TimeBeginPeriod(uint uMilliseconds);
[DllImport("winmm.dll", EntryPoint="timeEndPeriod", SetLastError=true)]
public static extern uint TimeEndPeriod(uint uMilliseconds);
public static void OptimizedMode()
{
caps = new TimeCaps();
if (TimeGetDevCaps(ref caps, (uint)System.Runtime.InteropServices.Marshal.SizeOf(caps)) != 0)
{
Console.WriteLine("StopWatch: TimeGetDevCaps failed");
}
if (TimeBeginPeriod(caps.wPeriodMin) != 0)
{
Console.WriteLine("StopWatch: TimeBeginPeriod failed");
}
}
public static void EndOptimizedMode()
{
if (TimeEndPeriod(caps.wPeriodMin) != 0)
{
Console.WriteLine("StopWatch: TimeEndPeriod failed");
}
}
#endif
static Random random;
static void Main(string[] args)
{
#if WIN32
OptimizedMode();
#endif
random = new Random();
Console.WriteLine("Enter loop count:");
Console.WriteLine("999999");
string value = Console.ReadLine();
int count;
if (int.TryParse(value, out count))
{
runVector4Test(count);
}
else
{
Console.WriteLine("Invalide value: " + value);
}
#if WIN32
EndOptimizedMode();
#endif
Console.WriteLine("DONE");
Console.ReadLine();
}
static void runVector4Test(int count)
{
var values = new Vector4[count];
const double range = .01;
for (int i = 0; i != count; ++i)
{
values[i].X = (numf)(random.NextDouble() * range) + 1;
values[i].Y = (numf)(random.NextDouble() * range) + 1;
values[i].Z = (numf)(random.NextDouble() * range) + 1;
values[i].W = (numf)(random.NextDouble() * range) + 1;
}
Console.WriteLine("Waiting for GC...");
GC.Collect();
System.Threading.Thread.Sleep(5000);
Console.WriteLine("Starting Vector4 Test...");
var time = new Stopwatch();
long totalTime = 0;
Vector4 totalValue = new Vector4();
for (int i = 0; i != 100; ++i)
{
time.Restart();
for (int i2 = 0; i2 < count-1; ++i2)
{
Vector4 vec1 = values[i2];
Vector4 vec2 = values[i2+1];
totalValue += vec1;
totalValue -= vec2;
totalValue /= vec1;
totalValue *= vec2;
}
time.Stop();
totalTime += time.ElapsedMilliseconds;
}
Console.WriteLine("Vector4 Time: " + (totalTime / 100d));
Console.WriteLine("Vector4 Values: " + totalValue);
Console.WriteLine();
}
}
}
结果如下:
<<< AMD Athlon 64 X2 Dual Core 4600+ 2.40GHz >>>
{
.NET 4.5 (Win8-Win32) = 39.9 mil
Mono 3.2.3 (Win8-Win32) = 99.49 mil
Mono 3.2.3 (PC-Linux) = 146.87 mil
Mono 3.2.1 (PC-BSD) = 144 mil
}
<<< Intel Core2 Duo P8600 2.40GHz >>>
{
Mono 3.2.3 (OSX 10.9) = 98.54 mil
.NET 4.5 (Win7-Win32) = 38.47 mil
}
为什么 Linux 和 BSD 上的 Mono 运行速度比 Windows 和 OSX 上的 Mono 慢 1/3?
最佳答案
好的,我做了一个更好的基准测试(RayTraceBenchmark):https://github.com/zezba9000/RayTraceBenchmark (随意进行拉取请求以添加更多语言或发布端口 [希望看到结果])
它渲染 3D 场景并保存 RAW 图像文件。您可以通过 Photoshop 或其他任何方式打开图像。图片分辨率为1280x720。
以下是测试的当前结果:https://github.com/zezba9000/RayTraceBenchmark/blob/master/C%23/Results.md
如您所见,Linux/BSD 在同一台计算机上仍然运行速度较慢?这不应该发生?
<<< AMD Athlon 64 X2 Dual Core 4600+ 2.40GHz >>>
.NET 4.5 (Win8-Win32)
(x86) = 1.179 sec
(x64) = 1.549 sec
Mono 3.2.3 (Win8-Win32)
(x86) = 2.059 sec
(x64) = 2.07 sec
Mono 3.2.3 (PC-Linux)
(x86) = 2.425
(x64) = 2.409
Mono 3.2.1 (PC-BSD)
(x86) = 2.536
(x64) = 2.509
<<< Intel Core2 Duo P8600 2.40GHz >>>
.NET 4.5 (Win7-Win32)
(x86) = 1.05 sec
(x64) = 1.132 sec
Mono 3.2.3 (Win7-Win32)
(x86) = 1.692 sec
(x64) = 1.702 sec
Mono 3.2.3 (OSX 10.9)
(x86) = 1.675 sec
(x64) = 1.679 sec
关于.net - 为什么 Mono 在 Linux 和 BSD 上运行速度慢 1/3?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19714687/
我的应用程序中有以下查询: SELECT a.*, f.* FROM flights_database f JOIN airports a ON f.airport = a.airportNameCl
我们在使用 MySQL(以及 MariaDB)时遇到了一个奇怪的问题。一个简单的数据库,有 2 个表(InnoDB 引擎),都包含(以及其他一些)3 或 4 个带有 XML 数据的文本列。大小为 1-
我在 MySQL 上的执行路径上遇到问题,导致查询缓慢且不一致。这是一个全新的现象。我们还有其他具有完全相同(好吧,尽可能接近)设置的表,这很好,但出于某种原因,现在创建新表会遇到这个缓慢/不一致的问
我使用 Eclipse Marketplace 的下载速度始终非常慢(现在从 http://download.eclipse.org 开始,下载速度为 3 MB/s,下载速度为 25 kB/s),这使
我正在开发一个 Qt Creator 项目,其中包含大量头文件(点云库、Boost 等)。例如。 Boost 有大约 9000 个头文件。现在看来,包含的数量确实减慢了 IDE。代码完成很慢,大约。
我在一个项目中使用 document.elementFromPoint,它看起来很慢。 100,000 次迭代需要 7051 毫秒。 document.getElementsByTagName("*"
我有一个 tableView ,每行有四个图表,大约 20 行。当我尝试滚动表格时,我将删除现有图表并为每一行构建新图表。 此操作使 TableView 的滚动非常慢。任何使滚动速度更快以及加载新图表
我有一个如下所示的数据框: date,time,metric_x 2016-02-27,00:00:28.0000000,31 2016-02-27,00:01:19.0000000,40 2016-
TLDR:我的微调器瞬间显示了错误的颜色。 我的微调器有问题。每当我运行应用程序时,如果 Activity 没有缓存在内存中,它有时会滞后。在我可以将其设置为正确的颜色之前,文本是默认颜色(如黑色)。
我在使用 SELECT COUNT(*) 对大型表进行 SQLite 时遇到性能问题。 由于我还没有收到可用的答案并且我做了一些进一步的测试,所以我编辑了我的问题以纳入我的新发现。 我有 2 个表:
当音频因加载数据不足(速度慢)而暂停时,我可以使用什么事件? 就像: $audio.on('suspendToLoading',function(){ alert('loading...');
这是我的 MATLAB 程序的分析模拟运行结果。我需要运行此模拟数十万次(约 100,000 次)。 因此我需要一种更快的方法来读取 Excel 文件。 规范:Excel 文件由 10000x2 个单
每当与数据透视表交互时,Excel 都非常慢,这让我感到非常困难。添加/删除字段、更改过滤器或切片器,所有这些都需要 Excel 卡住几分钟才能响应。 看来生成的 MDX 效率极低。我可以理解他们必须
我正在使用 Entity Framework 来检索大型数据集。 数据集有parent/child关系,我需要和parent同时带回child信息。 我发现 EF 最初发送一个查询以获取父对象列表,然
我有一个使用 gridview 的应用程序,它非常慢。 添加 Trace=true 后对于页面,我追踪了时间花费的地方:在 GridView 上调用 BindData() 时。 GridView连接到
我编写了一个小代码来使用 QtCreator 测试 QGraphicsView 的功能。 代码非常简单,只是创建了一个继承自 QGraphicsView 的类,上面有一个 QGraphicsScene
后期以补充作品的形式自动加入成员(member)。数据库速度较慢。有没有办法加快这个速度?用户无所谓..除了自动补码之外如何停止写?(自动补码;城市输入。成员(member)表格位于。) 注册.php
我有一个文件 (insert.sql),其中有 250k 行,没有键,没有索引: INSERT `project_383`.`entity_metrics_build_1` VALUES ('d402
我最近开发了一个应用程序(java 8、spring-boot、hibernate、maven),它通过 REST API 公开数据库。我遇到的问题是数据库调用很慢(3000 毫秒以上),只是为了获取
我正在尝试在 Canvas 上使用旋转,我现在有了它,因此每个对象都有自己的旋转。如果没有它们旋转,我可以在一台非常低端的计算机上在屏幕上显示大约 400 个对象,在一台正常库存的计算机上显示近 20
我是一名优秀的程序员,十分优秀!