why c# is faster at this?

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++???
Benchmarks? Configuration options? Compile options?

(tl;dr: you are doing something that is killing C++’s performance.)
Try running the C++ code on release mode.
On my machine they are almost equal - release build with all optimizations.
C# 255 ms
C++ 256 ms
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
Topic archived. No new replies allowed.