[Mono-list] String comparisons slow
Bill Blinn
bblinn at gmail.com
Tue Jul 20 22:11:10 EDT 2010
Hi,
I was trying out some tests to check performance of mono with
multithreading and benchmark Windows .NET, Windows mono and Linux
(ubuntu 9.04) mono. The results I have show that string comparisons
are much slower on mono than on .NET (8x). Am I doing something wrong?
Thanks,
bill
Here are my results:
windows .net
Running test with 2 cores and 400000 items
***** MyApp.MultiCoreTests.TestMultiThreadInt
Beginning TestMultiThreadInt
TestMultiThreadInt Time 00:00:00.6490421
***** MyApp.MultiCoreTests.TestMultiThreadName
Beginning TestMultiThreadName
TestMultiThreadName Time 00:00:02.3353270
***** MyApp.MultiCoreTests.TestSingleThreadInt
Beginning TestSingleThreadInt
TestSingleThreadInt Time 00:00:01.0017084
***** MyApp.MultiCoreTests.TestSingleThreadString
Beginning TestSingleThreadString
TestSingleThreadString Time 00:00:04.6166498
windows mono
Running test with 2 cores and 400000 items
***** MyApp.MultiCoreTests.TestMultiThreadInt
Beginning TestMultiThreadInt
TestMultiThreadInt Time 00:00:00.3894325
***** MyApp.MultiCoreTests.TestMultiThreadName
Beginning TestMultiThreadName
TestMultiThreadName Time 00:00:16.9111039
***** MyApp.MultiCoreTests.TestSingleThreadInt
Beginning TestSingleThreadInt
TestSingleThreadInt Time 00:00:00.6319084
***** MyApp.MultiCoreTests.TestSingleThreadString
Beginning TestSingleThreadString
TestSingleThreadString Time 00:00:29.8346654
linux mono
ProcessModel: Default DomainUsage: Single
Execution Runtime: mono-2.0
Running test with 2 cores and 400000 items
.Beginning TestMultiThreadInt
TestMultiThreadInt Time 00:00:00.3695696
.Beginning TestMultiThreadName
TestMultiThreadName Time 00:00:18.2811198
.Beginning TestSingleThreadInt
TestSingleThreadInt Time 00:00:00.6757025
.Beginning TestSingleThreadString
TestSingleThreadString Time 00:00:33.9977345
----------------
and here is my code:
[TestFixture]
public class MultiCoreTests
{
private readonly TestObj[][] m_input = new
TestObj[Environment.ProcessorCount][];
private const int NUM_ITEMS = 400000;
[TestFixtureSetUp]
public void TestFixtureSetup()
{
if(Environment.ProcessorCount == 1)
throw new IgnoreException("Cannot run this
multithreaded test on a machine with only one core.");
Console.Out.WriteLine("Running test with {0} cores and {1}
items", Environment.ProcessorCount, NUM_ITEMS);
}
[SetUp]
public void SetUp()
{
var r = new Random(12345);
for (int i = 0; i < m_input.Length; i ++ )
{
m_input[i] = new TestObj[NUM_ITEMS];
for(var j = 0; j < m_input[i].Length; j++)
{
m_input[i][j] = new TestObj()
{
ID = r.Next(),
Name =
string.Format("TestObj-{0}-{1}", r.Next(), r.Next())
};
}
}
}
[Test]
public void TestSingleThreadInt()
{
Console.WriteLine("Beginning TestSingleThreadInt");
var stopwatch = new Stopwatch();
stopwatch.Start();
foreach (var t in m_input)
{
Array.Sort(t, (x, y) => x.ID.CompareTo(y.ID));
}
stopwatch.Stop();
Console.WriteLine("TestSingleThreadInt Time {0}",
stopwatch.Elapsed);
}
[Test]
public void TestSingleThreadString()
{
Console.WriteLine("Beginning TestSingleThreadString");
var stopwatch = new Stopwatch();
stopwatch.Start();
foreach (var t in m_input)
{
Array.Sort(t, (x, y) => x.Name.CompareTo(y.Name));
}
stopwatch.Stop();
Console.WriteLine("TestSingleThreadString Time {0}",
stopwatch.Elapsed);
}
[Test]
public void TestMultiThreadInt()
{
var threads = new List<Thread>();
for(var i = 0; i < Environment.ProcessorCount; i ++)
{
var i1 = i;
threads.Add(new Thread(
() => Array.Sort(m_input[i1],
(x, y) =>
x.ID.CompareTo(y.ID))));
}
Console.WriteLine("Beginning TestMultiThreadInt");
var stopwatch = new Stopwatch();
stopwatch.Start();
foreach (var thread in threads)
thread.Start();
foreach (var thread in threads)
thread.Join();
stopwatch.Stop();
Console.WriteLine("TestMultiThreadInt Time {0}", stopwatch.Elapsed);
}
[Test]
public void TestMultiThreadName()
{
var threads = new List<Thread>();
for (var i = 0; i < Environment.ProcessorCount; i++)
{
var i1 = i;
threads.Add(new Thread(
() => Array.Sort(m_input[i1],
(x, y) =>
x.Name.CompareTo(y.Name))));
}
Console.WriteLine("Beginning TestMultiThreadName");
var stopwatch = new Stopwatch();
stopwatch.Start();
foreach (var thread in threads)
thread.Start();
foreach (var thread in threads)
thread.Join();
stopwatch.Stop();
Console.WriteLine("TestMultiThreadName Time {0}",
stopwatch.Elapsed);
}
class TestObj
{
public int ID { get; set; }
public String Name { get; set; }
}
}
More information about the Mono-list
mailing list