[prev in list] [next in list] [prev in thread] [next in thread]
List: mono-devel-list
Subject: [Mono-dev] System.Decimal performance
From: "Leszek Ciesielski" <skolima () gmail ! com>
Date: 2008-05-29 14:06:00
Message-ID: 23a15590805290706m72bb8fcasc8fd0967b22dbb26 () mail ! gmail ! com
[Download RAW message or body]
Hi,
the company I work for builds finance-related software, so we use the
Decimal type a lot. And in any computation-heavy program we find that
the Mono implementation of the decimal type... well... let's just say
it's not on par with MS.Net performance ;-) . Addition, substraction
and multiplication lag a bit (2-4 times slower). However, division is
at least 10 times slower, in some cases even 50x! I don't have any
complex tests at hand right now, but a simple performance-measuring
program is attached to the mail. There's also a java version (although
BigDecimal is not a simple equivalent of System.Decimal as it has no
upper bound on available precision). From my simple test the results
are as follows:
MS.Net 3.5
addition 2375 ms : 2354,156132
substraction 2140,625 ms : 2337,043868
multiplication 1734,375 ms : 189,08461995264
division 8468,75 ms : 29097,233616240416508043573961
Mono 1.9 Windows 2.0 profile
addition 4812 ms : 2354,156132
substraction 4781 ms : 2337,043868
multiplication 3407 ms : 189,08461995264
division 61390 ms : 29097,233616240416508043573961
Mono svn-linux 2.0 profile
addition 4201.837 ms : 2354.156132
substraction 4413.458 ms : 2337.043868
multiplication 4489.036 ms : 189.08461995264
division 61303.573 ms : 29097.233616240416508043573961
Java 1.6.0_06
addition 4640 ms : 2354.156132
substraction 3969 ms : 2337.043868
multiplication 2219 ms : 189.08461995264
division 33376 ms : 29097.233616240416508043573961
Has anyone done any performance tunining with the decimal type?
Regards,
Leszek 'skolima' Ciesielski
--
MS-DOS user since 5.0
Windows user since 3.11
Linux user since kernel 2.4
Novell Netware user since 2.2
WARCRAFT user since 1.0
["Program.cs" (text/plain)]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DecimalSpeed
{
class Program
{
static void Main(string[] args)
{
Addition();
Substraction();
Multiplication();
Division();
}
private static void Division()
{
decimal a = 0, b = 0, c = 0, d = 1;
DateTime start = DateTime.UtcNow;
a = 2345.6m;
b = 0.009432m;
c = 8.5467m;
d = a / b / c;
for (int i = 0; i < 10000000; i++)
d = a / b / c;
DateTime stop = DateTime.UtcNow;
Console.WriteLine("division {0} ms : {1}", (stop - start).TotalMilliseconds, d);
}
private static void Multiplication()
{
decimal a = 0, b = 0, c = 0, d = 1;
DateTime start = DateTime.UtcNow;
a = 2345.6m;
b = 0.009432m;
c = 8.5467m;
d = a * b * c;
for (int i = 0; i < 10000000; i++)
d = a * b * c;
DateTime stop = DateTime.UtcNow;
Console.WriteLine("multiplication {0} ms : {1}", (stop - start).TotalMilliseconds, d);
}
private static void Substraction()
{
decimal a = 0, b = 0, c = 0, d = 1;
DateTime start = DateTime.UtcNow;
a = 2345.6m;
b = 0.009432m;
c = 8.5467m;
d = a - b - c;
for (int i = 0; i < 10000000; i++)
d = a - b - c;
DateTime stop = DateTime.UtcNow;
Console.WriteLine("substraction {0} ms : {1}", (stop - start).TotalMilliseconds, d);
}
private static void Addition()
{
decimal a = 0, b = 0, c = 0, d = 1;
DateTime start = DateTime.UtcNow;
a = 2345.6m;
b = 0.009432m;
c = 8.5467m;
d = a + b + c;
for (int i = 0; i < 10000000; i++)
d = a + b + c;
DateTime stop = DateTime.UtcNow;
Console.WriteLine("addition {0} ms : {1}", (stop - start).TotalMilliseconds, d);
}
}
}
["Program.java" (text/plain)]
import java.math.BigDecimal;
import java.math.RoundingMode;
public class Program {
public static void main(String[] args) {
Addition();
Substraction();
Multiplication();
Division();
}
private static void Division() {
BigDecimal a, b, c, d;
long start = System.currentTimeMillis();
a = new BigDecimal("2345.6");
b = new BigDecimal("0.009432");
c = new BigDecimal("8.5467");
// this is the rounding mode used by System.Decimal by default
d = a.divide(b, 24, RoundingMode.HALF_EVEN).divide(c, 24,
RoundingMode.HALF_EVEN);
for (int i = 0; i < 10000000; i++)
d = a.divide(b, 24, RoundingMode.HALF_EVEN).divide(c, 24,
RoundingMode.HALF_EVEN);
long stop = System.currentTimeMillis();
System.out.println("division " + (stop - start) + " ms : " + d);
}
private static void Multiplication() {
BigDecimal a, b, c, d;
long start = System.currentTimeMillis();
a = new BigDecimal("2345.6");
b = new BigDecimal("0.009432");
c = new BigDecimal("8.5467");
d = a.multiply(b).multiply(c);
for (int i = 0; i < 10000000; i++)
d = a.multiply(b).multiply(c);
long stop = System.currentTimeMillis();
System.out.println("multiplication " + (stop - start) + " ms : " + d);
}
private static void Substraction() {
BigDecimal a, b, c, d;
long start = System.currentTimeMillis();
a = new BigDecimal("2345.6");
b = new BigDecimal("0.009432");
c = new BigDecimal("8.5467");
d = a.subtract(b).subtract(c);
for (int i = 0; i < 10000000; i++)
d = a.subtract(b).subtract(c);
long stop = System.currentTimeMillis();
System.out.println("substraction " + (stop - start) + " ms : " + d);
}
private static void Addition() {
BigDecimal a, b, c, d;
long start = System.currentTimeMillis();
a = new BigDecimal("2345.6");
b = new BigDecimal("0.009432");
c = new BigDecimal("8.5467");
d = a.add(b).add(c);
for (int i = 0; i < 10000000; i++)
d = a.add(b).add(c);
long stop = System.currentTimeMillis();
System.out.println("addition " + (stop - start) + " ms : " + d);
}
}
_______________________________________________
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic