Click here to Skip to main content
15,910,471 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
GeneralRe: How do I change application-scoped settings Pin
Luc Pattyn15-Mar-10 7:55
sitebuilderLuc Pattyn15-Mar-10 7:55 
QuestionFail to install Sliverlight3 tools for VS2008 SP1 Pin
Shahdat Hosain12-Mar-10 3:21
Shahdat Hosain12-Mar-10 3:21 
AnswerRe: Fail to install Sliverlight3 tools for VS2008 SP1 Pin
Abhinav S12-Mar-10 4:02
Abhinav S12-Mar-10 4:02 
QuestionBrowsing website on blackberry Pin
neer112-Mar-10 2:53
neer112-Mar-10 2:53 
AnswerRe: Browsing website on blackberry Pin
Dave Kreskowiak12-Mar-10 3:15
mveDave Kreskowiak12-Mar-10 3:15 
QuestionAnyone know how you can create a screen that looks like the Outlook calendar 2007 Pin
RadyShishi12-Mar-10 1:38
RadyShishi12-Mar-10 1:38 
AnswerRe: Anyone know how you can create a screen that looks like the Outlook calendar 2007 Pin
Eddy Vluggen12-Mar-10 2:26
professionalEddy Vluggen12-Mar-10 2:26 
Questionparallel processing Pin
Tiju John11-Mar-10 23:31
Tiju John11-Mar-10 23:31 
Parallel processing is supposed to increase performance, not decrease.
Am I missing something??? Any explanations for slower parallel performance.

(I have a Intel core2 duo processor with 2 CPU’s. System.Environment.ProcessorCount = 2)

Thanks
Tiju



using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ParallelConsole
{
    class Program
    {
        static bool IsPrime(double x)
        {
            if (x < 2) return false;

            double sqrroot = Math.Ceiling(Math.Sqrt(x));
            bool isPrime = true;

            for (int i = 2; i <= sqrroot; i++)
            {
                if (x % i == 0)
                {
                    isPrime = false;
                    break;
                }
            }
            return isPrime;
        }

        static void helper(double i, DateTime dt)
        {
            if (i != 1)
                i = 3;

            while (i > 0 && i <= 100000)
            {
                if (IsPrime(i))
                    Console.WriteLine(i.ToString() + " : " + DateTime.Now.Subtract(dt).ToString());

                i += 4;
            }
        }

        static void Main(string[] args)
        {

            Console.WriteLine("Finding prime numbers(from 1.). Press Enter to start!");
            Console.ReadLine();

            DateTime startTimeSequential; TimeSpan sq = new TimeSpan();
            DateTime startTimeParallel; TimeSpan prl = new TimeSpan();

            //sequential
            startTimeSequential = DateTime.Now;
            for (int i = 1; i <= 2; i++)//loop two times
            {
                helper(i, startTimeSequential); // 1 for odd, 2 for alternate odd. check the numbers in two streams               
            }
            sq = DateTime.Now.Subtract(startTimeSequential);


            //parallel
            startTimeParallel = DateTime.Now;
            Parallel.For(1, 3, (i => { helper(i, startTimeParallel); }));

            prl = DateTime.Now.Subtract(startTimeParallel);
            Console.WriteLine("Total time sequential = " + sq.ToString());
            Console.WriteLine("Total time parallel (2) = " + prl.ToString());



            Console.ReadLine();
        }
    }
}

AnswerRe: parallel processing Pin
Eddy Vluggen12-Mar-10 1:01
professionalEddy Vluggen12-Mar-10 1:01 
GeneralRe: parallel processing Pin
Tiju John12-Mar-10 3:16
Tiju John12-Mar-10 3:16 
AnswerRe: parallel processing Pin
Dave Kreskowiak12-Mar-10 2:00
mveDave Kreskowiak12-Mar-10 2:00 
GeneralRe: parallel processing Pin
Tiju John12-Mar-10 3:20
Tiju John12-Mar-10 3:20 
GeneralRe: parallel processing Pin
Dave Kreskowiak12-Mar-10 5:09
mveDave Kreskowiak12-Mar-10 5:09 
AnswerRe: parallel processing Pin
frito_burrito12-Mar-10 4:39
frito_burrito12-Mar-10 4:39 
GeneralRe: parallel processing Pin
harold aptroot12-Mar-10 5:15
harold aptroot12-Mar-10 5:15 
GeneralRe: parallel processing Pin
Luc Pattyn12-Mar-10 6:15
sitebuilderLuc Pattyn12-Mar-10 6:15 
GeneralRe: parallel processing Pin
harold aptroot12-Mar-10 6:35
harold aptroot12-Mar-10 6:35 
GeneralRe: parallel processing Pin
Luc Pattyn12-Mar-10 6:49
sitebuilderLuc Pattyn12-Mar-10 6:49 
GeneralRe: parallel processing Pin
harold aptroot12-Mar-10 7:04
harold aptroot12-Mar-10 7:04 
GeneralRe: parallel processing Pin
Luc Pattyn12-Mar-10 7:43
sitebuilderLuc Pattyn12-Mar-10 7:43 
GeneralRe: parallel processing Pin
harold aptroot12-Mar-10 7:47
harold aptroot12-Mar-10 7:47 
GeneralRe: parallel processing Pin
Luc Pattyn12-Mar-10 7:53
sitebuilderLuc Pattyn12-Mar-10 7:53 
GeneralRe: parallel processing Pin
harold aptroot12-Mar-10 8:01
harold aptroot12-Mar-10 8:01 
GeneralRe: parallel processing Pin
Dave Kreskowiak12-Mar-10 8:09
mveDave Kreskowiak12-Mar-10 8:09 
GeneralRe: parallel processing Pin
Luc Pattyn12-Mar-10 8:37
sitebuilderLuc Pattyn12-Mar-10 8:37 

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.