Jump to content

c# Multithreading need help...

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
2 replies to this topic

#1
jtx

jtx

    Newbie

  • Members
  • Pip
  • 2 posts
i am editing a cpu benchmark code at the moment and have problems with multi threading, using one thread i get about 740 points on my E6750 3.2Ghz with two i get 720 i know spawning another thread costs some time too, but why isnt it much faster? Can anyone more experienced than I please look at the code:

private void startbench_Click(object sender, EventArgs e)
        {
            startbench.Enabled = false;
            button2.Visible = true;
            button4.Visible = false;
            button2.Enabled = false;
            gui.ActiveForm.Refresh();
            Thread.Sleep(200);
            progressbargui.ShowTitle("Core v0.7 calculating...");
            progressbargui.ShowInTaskbar = false;
            progressbargui.Visible = true;
            int value = 0;
            progressbargui.value(value);
            //PointsA = CalculateE(0);
            int value1 = 20;
            progressbargui.value(value1);
            progressbargui.Refresh();
            Thread.Sleep(100);
            //PointsA += CalculateT(0);
            int value2 = 35;
            progressbargui.value(value2);
            progressbargui.Refresh();
            Thread.Sleep(100);
            PointsA += CalculateR_Two(0);
            int value2a = 50;
            progressbargui.value(value2a);
            progressbargui.Refresh();
            Thread.Sleep(100);
            //PointsA += CalculateR_Blow(0);
            int value2b = 69;
            progressbargui.value(value2b);
            progressbargui.Refresh();
            Thread.Sleep(100);
            //PointsA += CalculateR_SHA(0);
            int value3 = 100;
            progressbargui.value(value3);
            progressbargui.Refresh();
            Thread.Sleep(100);
            progressbargui.Visible = false;
}

public long CalculateR_Two(int Threads)
        {
            long PointsR_Two = 0;
            DateTime begin = DateTime.Now;
            Thread[] newThreads = new Thread[0];
            for (int i = 0; i < newThreads.Length; i++)
            {
                newThreads[i] =
                new Thread(new ThreadStart(CalcR.CalcR_Two));
                newThreads[i].Start();
            }
            CalcR.CalcR_Two();
            DateTime end = DateTime.Now;
            System.TimeSpan number1 = end - begin;
            PointsR_Two = 1000 * 245 / (number1.Ticks / 1000000);
            return PointsR_Two;
        }

public static void CalcR_Two()
                {
                    String random = @"asohaoishoagdoagdouagudagodgoaudgoaugdoaugdoagdoaugdouagduag
                                  skjdosjdpajdpjasodasjpodjpasojdpoajojjpdjojosapojojpjjoopajd
                                  dsodjspojcposjpconspcnpsoncposnpsnpcoponsoconpnsonsoopsopsmo
                                  kdsjkpnspkcnspknckpsdpijdpoijpojdposjdopsjpojspndposnpomopsa
                                  sèpajdoasmcmowqhyewpoie'qw93439436489fiousdiuh74030nkdh80220
                                  ksdahndioshbdoiahisdgghoigiysijipadishdhaodyhy6943dasodjao'2
                                  sdomposcpoasjcpiosahnfhry0qw493249073993rj3h9fh 99jf90jnfi3h
                                  dsodjspojcposjpconspcnpsoncposnpsnpcoponsoconpnsonsoopsopsmo
                                  skjdosjdpajdpjasodasjpodjpasojdpoajojjpdjojosapojojpjjoopajd
                                  kdsjkpnspkcnspknckpsdpijdpoijpojdposjdopsjpojspndposnpomopsa
                                  skjdosjdpajdpjasodasjpodjpasojdpoajojjpdjojosapojojpjjoopajd
                                  sdomposcpoasjcpiosahnfhry0qw493249073993rj3h9fh 99jf90jnfi3h
                                  kdsjkpnspkcnspknckpsdpijdpoijpojdposjdopsjpojspndposnpomopsa
                                  sdomposcpoasjcpiosahnfhry0qw493249073993rj3h9fh 99jf90jnfi3h
                                  kdsjkpnspkcnspknckpsdpijdpoijpojdposjdopsjpojspndposnpomopsa
                                  sdomposcpoasjcpiosahnfhry0qw493249073993rj3h9fh 99jf90jnfi3h
                                  skjdosjdpajdpjasodasjpodjpasojdpoajojjpdjojosapojojpjjoopajd
                                  skjdosjdpajdpsafasfasifpaspfjh0972342 '4'v 'f9cndvdf543657ds
                                  49047120394709127472h90hhpasojdpoajojjpdjojosapojojpjjoopajd
                                  kdsjkpnspkcnspknckpsdpijdpoijpojdposjdopsjpojspndposnpomopsa";

                    XCryptEngine Engine = new XCryptEngine(XCryptEngine.AlgorithmType.Twofish);
                    for (int zi = 0; zi < 3; zi++)
                    {
                        for (int iz = 1; iz < 9500; iz++)//2561
                        {
                            Engine.Key = "abcdefghilmnopqrstuvz";
                            Engine.InitializeEngine();
                            Engine.Encrypt(random);
                            Engine.DestroyEngine();
                        }
                    }
                }


#2
amrosama

amrosama

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 8,674 posts
  Thread[] newThreads = new Thread[0];
you are using one thread, it will make no difference, did you try using more than one?
yo homie i heard you like one-line codes so i put a one line code that evals a decrypted one line code that prints "i love one line codes"
eval(base64_decode("cHJpbnQgJ2kgbG92ZSBvbmUtbGluZSBjb2Rlcyc7"));
www.amrosama.com | the unholy methods of javascript

#3
Termana

Termana

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 4,057 posts
Either way it won't make a difference. When doing multi-threading you need to learn how multi-threading works. The operating system is responsible for having the threads on separate cores, even if you make a new thread it is not guaranteed that it will go on the other core and so you may still be operating on the one core. Multi-threading is only really necessary and useful in CPU-intensive applications.

Interested in participating in community events?
Want to harness your programming skill and turn it into absolute prowess?
Come join our programming events!