Click here to Skip to main content
15,892,005 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: CCC OTD 2016-02-02 Solution Pin
OriginalGriff2-Feb-16 2:44
mveOriginalGriff2-Feb-16 2:44 
GeneralRe: CCC OTD 2016-02-02 Solution Pin
HobbyProggy2-Feb-16 2:48
professionalHobbyProggy2-Feb-16 2:48 
GeneralRe: CCC OTD 2016-02-02 Solution Pin
pkfox2-Feb-16 3:50
professionalpkfox2-Feb-16 3:50 
GeneralRe: CCC OTD 2016-02-02 Solution Pin
Duncan Edwards Jones2-Feb-16 2:37
professionalDuncan Edwards Jones2-Feb-16 2:37 
GeneralRe: CCC OTD 2016-02-02 Solution Pin
OriginalGriff2-Feb-16 2:40
mveOriginalGriff2-Feb-16 2:40 
GeneralRe: CCC OTD 2016-02-02 Solution Pin
Kornfeld Eliyahu Peter2-Feb-16 3:16
professionalKornfeld Eliyahu Peter2-Feb-16 3:16 
PraiseRe: CCC OTD 2016-02-02 Solution Pin
pkfox2-Feb-16 3:45
professionalpkfox2-Feb-16 3:45 
GeneralEveryone says c++ is faster than c#, why? Pin
amagitech2-Feb-16 1:10
amagitech2-Feb-16 1:10 
I used same algorithm for c# and c++. I have read c++ is faster than c# but my tests shows c# is faster than c++.
What's wrong? My codes like this.

c++ is 36 seconds
C++
#include<iostream>
#include<time.h>

using namespace std;

int main(){
	const clock_t beginTime = clock();
	for (int i = 2; i < 2000000; i++)
	{		
		bool isPrime = true;
		for (int j = 2; j*j <= i; j++)
		{
			if (i%j == 0){
				isPrime = false;
				break;
			}
		}
		if (isPrime)
			cout << i << endl;		
	}
	cout << float(clock() - beginTime) / CLOCKS_PER_SEC;
}


c# is 9 seconds
C#
using System;

namespace Console01
{
    class Program
    {

        static void Main(string[] args)
        {
            DateTime beginTime = DateTime.Now;
            for (int i = 2; i <= 2000000; i++)
            {
                bool isPrime = true;
                for (int j = 2; j * j < i; j++)
                {
                    if (i % j == 0)
                    {
                        isPrime = false;
                        break;
                    }
                }
                if (isPrime)
                    Console.WriteLine(i);
            }
            TimeSpan ts = DateTime.Now - beginTime;
            Console.WriteLine(ts.Seconds);
        }

    }
}

GeneralRe: Everyone says c++ is faster than c#, why? Pin
phil.o2-Feb-16 1:22
professionalphil.o2-Feb-16 1:22 
GeneralRe: Everyone says c++ is faster than c#, why? PinPopular
ZurdoDev2-Feb-16 1:30
professionalZurdoDev2-Feb-16 1:30 
GeneralRe: Everyone says c++ is faster than c#, why? Pin
phil.o2-Feb-16 1:34
professionalphil.o2-Feb-16 1:34 
GeneralRe: Everyone says c++ is faster than c#, why? Pin
#realJSOP2-Feb-16 2:42
mve#realJSOP2-Feb-16 2:42 
GeneralRe: Everyone says c++ is faster than c#, why? Pin
Ygnaiih3-Feb-16 2:26
professionalYgnaiih3-Feb-16 2:26 
GeneralRe: Everyone says c++ is faster than c#, why? Pin
ZurdoDev3-Feb-16 3:17
professionalZurdoDev3-Feb-16 3:17 
GeneralRe: Everyone says c++ is faster than c#, why? Pin
Ygnaiih3-Feb-16 3:40
professionalYgnaiih3-Feb-16 3:40 
GeneralRe: Everyone says c++ is faster than c#, why? Pin
ZurdoDev3-Feb-16 3:42
professionalZurdoDev3-Feb-16 3:42 
GeneralRe: Everyone says c++ is faster than c#, why? Pin
James Lonero4-Feb-16 13:02
James Lonero4-Feb-16 13:02 
GeneralRe: Everyone says c++ is faster than c#, why? Pin
Jeremy Falcon2-Feb-16 6:05
professionalJeremy Falcon2-Feb-16 6:05 
GeneralRe: Everyone says c++ is faster than c#, why? PinPopular
Maximilien2-Feb-16 2:41
Maximilien2-Feb-16 2:41 
GeneralRe: Everyone says c++ is faster than c#, why? Pin
Anthony Mushrow2-Feb-16 1:43
professionalAnthony Mushrow2-Feb-16 1:43 
GeneralRe: Everyone says c++ is faster than c#, why? Pin
Sascha Lefèvre2-Feb-16 1:53
professionalSascha Lefèvre2-Feb-16 1:53 
GeneralRe: Everyone says c++ is faster than c#, why? Pin
Stefan_Lang2-Feb-16 21:19
Stefan_Lang2-Feb-16 21:19 
GeneralRe: Everyone says c++ is faster than c#, why? Pin
Rio Rico Rick3-Feb-16 4:02
Rio Rico Rick3-Feb-16 4:02 
GeneralRe: Everyone says c++ is faster than c#, why? Pin
petek19553-Feb-16 5:15
petek19553-Feb-16 5:15 
GeneralRe: Everyone says c++ is faster than c#, why? Pin
jrobb2293-Feb-16 12:38
jrobb2293-Feb-16 12:38 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.