分散関数呼び出し
Posted feedbacks - C#
同一マシンのCoreDuo1.5GHz で1万回11秒
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | // サーバ
using System;
using System.Web.Services;
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class Service : System.Web.Services.WebService
{
[WebMethod]
public string Calc(int n, int r) {
int p = n * (100 - r) / 100;
return string.Format("販売価格 {0}円 (定価{1}円から{2}%引き)",
p.ToString("C").Substring(1), n.ToString("C").Substring(1), r);
}
}
// クライアント
using System;
using System.Diagnostics;
using HowWrite.localhost;
class Program
{
static void Main()
{
Service srv = new Service();
Stopwatch st = new Stopwatch();
st.Start();
string s = "";
for (int i = 0; i < 10000; ++i) s = srv.Calc(2000, 20);
Console.WriteLine(s);
st.Stop();
Console.WriteLine(st.ElapsedMilliseconds / 1000);
}
}
|
.NET Remoting版 CoreDuo 1.5GHz の同一マシンで1万回2.7秒
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | // サーバ用
using System;
public class Server : MarshalByRefObject
{
public string Calc(int n, int r)
{
int p = n * (100 - r) / 100;
return string.Format("販売価格 {0}円 (定価{1}円から{2}%引き)",
p.ToString("C").Substring(1), n.ToString("C").Substring(1), r);
}
}
class Program
{
static void Main()
{
System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel(
new System.Runtime.Remoting.Channels.Tcp.TcpChannel(50000), false);
System.Runtime.Remoting.RemotingConfiguration
.RegisterWellKnownServiceType(typeof(Server), "HowWrite",
System.Runtime.Remoting.WellKnownObjectMode.Singleton);
System.Console.ReadKey();
}
}
// クライアント用
using System;
using System.Diagnostics;
class Program
{
static void Main()
{
Server svr = (Server)Activator.GetObject(typeof(Server),
"tcp://localhost:50000/HowWrite");
Stopwatch st = new Stopwatch();
st.Start();
string s = "";
for (int i = 0; i < 10000; ++i) s = svr.Calc(2000, 20);
Console.WriteLine(s);
st.Stop();
Console.WriteLine(st.ElapsedMilliseconds / 1000.0);
}
}
|

沢渡 みかげ
#3401()
Rating0/0=0.00
[ reply ]