[C #] Performance Comparison Between httpcontext. cache and appfabric

Source: Internet
Author: User

Httpcontext

// Write
Stopwatch Sw = New Stopwatch ();
Sw. Start ();

For ( Int I = 1 ; I <= 100000 ; I ++)
{
VaR M = New MAN ()
{
Age = 1 ,
Height = 2
};
Httpcontext. Current. cache [I. tostring ()] = m;
}

Sw. Stop ();
Debug. writeline (SW. elapsedmilliseconds );

//Read
Sw. Start ();

For(IntJ =1; J <=100000; J ++)
{
VaRM = httpcontext. Current. cache [J. tostring ()];
}

Sw. Stop ();

Debug. writeline (SW. elapsedmilliseconds );

 

The result is:

181

249

 

Appfabric

VaR DCF = New Datacachefactory ();
VaR Cache = DCF. getcache ( " Default " );

//Write
Stopwatch Sw =NewStopwatch ();
Sw. Start ();

For ( Int I = 1 ; I <= 100000 ; I ++)
{
VaR M = New MAN ()
{
Age = 1 ,
Height = 2
};
Cache. Put (I. tostring (), M );
}

Sw. Stop ();
Debug. writeline (SW. elapsedmilliseconds );

//Read
Sw. Start ();

For(IntJ =1; J <=100000; J ++)
{
VaRM = cache. Get (J. tostring ());
}

Sw. Stop ();

Debug. writeline (SW. elapsedmilliseconds );

The result is

133979 (write time)

263803 (total read + write time)

 

Supplement the test result of application:

103184

 

 //Write

Stopwatch Sw = New Stopwatch ();
Sw. Start ();

For ( Int I = 1 ; I <= 100000 ; I ++)
{
VaR M = New MAN ()
{
Age = 1 ,
Height = 2
};
Application [I. tostring ()] = m;
}

Sw. Stop ();
Debug. writeline (SW. elapsedmilliseconds );

//Read
Sw. Start ();

For(IntJ =1; J <=100000; J ++)
{
VaRM = application [J. tostring ()];
}

Sw. Stop ();
Debug. writeline (SW. elapsedmilliseconds );

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.