why c# is faster at this?
Sep 7, 2017 at 6:39am UTC
this is c++:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#include "stdafx.h"
#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
float n, i;
cin >> n;
for (i = 0.1; i <= n; i += 0.1)
cout << i << " " ;
_getch();
return 0;
}
and this is c#:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
class Program
{
static void Main(string[] args)
{
float n, i;
n = (float )Convert.ToDouble(Console.ReadLine());
try
{
for (i = 0.1F; i <= n; i += 0.1F)
Console.Write(i+"-" );
}
catch (Exception ex)
{
}
Console.ReadLine();
}
}
why c# run this code faster than C++???
Sep 7, 2017 at 7:38am UTC
Benchmarks? Configuration options? Compile options?
(tl;dr: you are doing something that is killing C++’s performance.)
Sep 7, 2017 at 8:07am UTC
Try running the C++ code on release mode.
Sep 7, 2017 at 8:23am UTC
On my machine they are almost equal - release build with all optimizations.
C# 255 ms
C++ 256 ms
Sep 7, 2017 at 9:10am UTC
you are doing something that is killing C++’s performance
what work?
i like to know why?
thomas tested it and he saw this result too.
Last edited on Sep 7, 2017 at 3:50pm UTC
Topic archived. No new replies allowed.