|
@@ -11,6 +11,8 @@ namespace Benchmarks.AspNet.Controllers
|
|
|
{
|
|
|
public class AdoController : Controller
|
|
|
{
|
|
|
+ Random random = new Random();
|
|
|
+
|
|
|
private DbConnection CreateConnection(string providerName)
|
|
|
{
|
|
|
ConnectionStringSettings connectionSettings = ConfigurationManager.ConnectionStrings[providerName];
|
|
@@ -22,7 +24,7 @@ namespace Benchmarks.AspNet.Controllers
|
|
|
|
|
|
public ActionResult Index(string providerName, int? queries)
|
|
|
{
|
|
|
- List<World> worlds = new List<World>(queries ?? 1);
|
|
|
+ List<World> worlds = new List<World>(Math.Max(1, Math.Min(500, queries ?? 1)));
|
|
|
|
|
|
using (DbConnection connection = CreateConnection(providerName))
|
|
|
{
|
|
@@ -31,9 +33,7 @@ namespace Benchmarks.AspNet.Controllers
|
|
|
using (DbCommand command = connection.CreateCommand())
|
|
|
{
|
|
|
command.CommandText = "SELECT * FROM World WHERE id = @ID";
|
|
|
-
|
|
|
- Random random = new Random();
|
|
|
-
|
|
|
+
|
|
|
for (int i = 0; i < worlds.Capacity; i++)
|
|
|
{
|
|
|
int randomID = random.Next(0, 10000) + 1;
|
|
@@ -49,11 +49,11 @@ namespace Benchmarks.AspNet.Controllers
|
|
|
{
|
|
|
if (reader.Read())
|
|
|
{
|
|
|
- World world = new World();
|
|
|
- world.id = reader.GetInt32(0);
|
|
|
- world.randomNumber = reader.GetInt32(1);
|
|
|
-
|
|
|
- worlds.Add(world);
|
|
|
+ worlds.Add(new World
|
|
|
+ {
|
|
|
+ id = reader.GetInt32(0),
|
|
|
+ randomNumber = reader.GetInt32(1)
|
|
|
+ });
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -80,13 +80,11 @@ namespace Benchmarks.AspNet.Controllers
|
|
|
{
|
|
|
while (reader.Read())
|
|
|
{
|
|
|
- Fortune fortune = new Fortune
|
|
|
+ fortunes.Add(new Fortune
|
|
|
{
|
|
|
ID = reader.GetInt32(0),
|
|
|
Message = reader.GetString(1)
|
|
|
- };
|
|
|
-
|
|
|
- fortunes.Add(fortune);
|
|
|
+ });
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -97,5 +95,67 @@ namespace Benchmarks.AspNet.Controllers
|
|
|
|
|
|
return View("Fortunes", fortunes);
|
|
|
}
|
|
|
+
|
|
|
+ public ActionResult Update(string providerName, int? queries)
|
|
|
+ {
|
|
|
+ List<World> worlds = new List<World>(Math.Max(1, Math.Min(500, queries ?? 1)));
|
|
|
+
|
|
|
+ using (DbConnection connection = CreateConnection(providerName))
|
|
|
+ {
|
|
|
+ connection.Open();
|
|
|
+
|
|
|
+ using (DbCommand selectCommand = connection.CreateCommand(),
|
|
|
+ updateCommand = connection.CreateCommand())
|
|
|
+ {
|
|
|
+ selectCommand.CommandText = "SELECT * FROM World WHERE id = @ID";
|
|
|
+ updateCommand.CommandText = "UPDATE World SET randomNumber = @Number WHERE id = @ID";
|
|
|
+
|
|
|
+ for (int i = 0; i < worlds.Capacity; i++)
|
|
|
+ {
|
|
|
+ int randomID = random.Next(0, 10000) + 1;
|
|
|
+ int randomNumber = random.Next(0, 10000) + 1;
|
|
|
+
|
|
|
+ DbParameter idParameter = selectCommand.CreateParameter();
|
|
|
+ idParameter.ParameterName = "@ID";
|
|
|
+ idParameter.Value = randomID;
|
|
|
+
|
|
|
+ selectCommand.Parameters.Clear();
|
|
|
+ selectCommand.Parameters.Add(idParameter);
|
|
|
+
|
|
|
+ World world = null;
|
|
|
+
|
|
|
+ using (DbDataReader reader = selectCommand.ExecuteReader(CommandBehavior.SingleRow))
|
|
|
+ {
|
|
|
+ if (reader.Read())
|
|
|
+ {
|
|
|
+ world = new World
|
|
|
+ {
|
|
|
+ id = reader.GetInt32(0),
|
|
|
+ randomNumber = reader.GetInt32(1)
|
|
|
+ };
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (world == null)
|
|
|
+ continue;
|
|
|
+
|
|
|
+ DbParameter numberParameter = updateCommand.CreateParameter();
|
|
|
+ numberParameter.ParameterName = "@Number";
|
|
|
+ numberParameter.Value = randomNumber;
|
|
|
+
|
|
|
+ updateCommand.Parameters.Clear();
|
|
|
+ updateCommand.Parameters.Add(idParameter);
|
|
|
+ updateCommand.Parameters.Add(numberParameter);
|
|
|
+
|
|
|
+ updateCommand.ExecuteNonQuery();
|
|
|
+
|
|
|
+ world.randomNumber = randomNumber;
|
|
|
+ worlds.Add(world);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return Json(worlds, JsonRequestBehavior.AllowGet);
|
|
|
+ }
|
|
|
}
|
|
|
}
|