strange performance of nested virtual methods
From: Markus Vogel (mail.mv_at_arcor.de)
Date: 03/16/05
- Next message: Alejandro Lapeyre: "Re: Info"
- Previous message: Jon Skeet [C# MVP]: "Re: Why does a DataSet need to have a finalizer?"
- Next in thread: Kismet: "RE: strange performance of nested virtual methods"
- Reply: Kismet: "RE: strange performance of nested virtual methods"
- Messages sorted by: [ date ] [ thread ]
Date: 16 Mar 2005 15:18:04 -0800
I wanted to decorate the features of a base class by declaring a
virtual method and deriving a new class, which overrides this method.
As I implemented this I found a strange performance behavior, that
occours as soon as I start nesting this concept.
I call this "strange performance behavior" because the extra cost of
calling time per nesting level is very irregular.
The following Table illustrates this.
nesting level extra calling time for the added level
1 500ms
2 1300ms
3 2400ms
4 500ms
5 500ms
6 500ms
7 500ms
. .
. .
. .
I found this behviour on three different machines but I can't find any
explaination.
Here comes what I'm doing
// This is my base class
public class Service
{
int val;
public virtual void SetValue(int val)
{
this.val = val;
}
}
// This is my derived class (mind the constructor)
public class ServiceDecorator : Service
{
Service baseService;
public ServiceDecorator(Service baseService)
{
this.baseService = baseService;
}
public override void SetValue(int val)
{
baseService.SetValue(val + 10);
}
}
// And this is my test-class
public class DecoratorTest
{
public static void Call_SetVal(Service service)
{
const int count = 100000000;
int tick;
tick = Environment.TickCount;
for(int a=0; a<count; a++)
{
service.SetValue(a);
}
tick = Environment.TickCount - tick;
Console.WriteLine(tick.ToString());
}
public static void RunTest()
{
Service service = new Service();
// this takes 541ms
DecoratorTest.Call_SetVal(service);
service = new ServiceDecorator(service);
// this takes 1051ms
DecoratorTest.Call_SetVal(service);
service = new ServiceDecorator(service);
// this takes 2414ms
DecoratorTest.Call_SetVal(service);
service = new ServiceDecorator(service);
// this takes 4706ms
DecoratorTest.Call_SetVal(service);
service = new ServiceDecorator(service);
// this takes 5128ms
DecoratorTest.Call_SetVal(service);
service = new ServiceDecorator(service);
// this takes 5638ms
DecoratorTest.Call_SetVal(service);
service = new ServiceDecorator(service);
// this takes 6139ms
DecoratorTest.Call_SetVal(service);
}
}
Any Ideas?
Thanks in advance,
Markus
- Next message: Alejandro Lapeyre: "Re: Info"
- Previous message: Jon Skeet [C# MVP]: "Re: Why does a DataSet need to have a finalizer?"
- Next in thread: Kismet: "RE: strange performance of nested virtual methods"
- Reply: Kismet: "RE: strange performance of nested virtual methods"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|