java mysql与.net MSSQL性能测试
java mysql 插入1W条数据代码
public static void main(String[] args) {
Connection conn = null;
Statement stmt = null;
try {
conn = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/myjava", "root", "123456");
stmt = conn.createStatement();
long starTime;
long endTime;
starTime = java.util.Calendar.getInstance().getTimeInMillis();
for (int i = 0; i < 10000; i++) {
stmt.executeUpdate("insert into users(Name,Password,Address) values('用户"
+ i + "','密码" + i + "','地址" + i + "')");
}
endTime = java.util.Calendar.getInstance().getTimeInMillis();
System.out.println((endTime - starTime) + "毫秒");
} catch (Exception e) {
}
}
.NET插入MSSQL 1W条数据代码
static void Main(string[] args)
{
string strCon = "server=.;database=Myjava;integrated security=sspi";
using (SqlConnection conn = new SqlConnection(strCon))
{
conn.Open();
SqlCommand cmd = conn.CreateCommand();
DateTime starTime = DateTime.Now;
for (int i = 0; i < 10000; i++)
{
cmd.CommandText = "insert into users(Name,Password,Address) values('用户"
+ i + "','密码" + i + "','地址" + i + "')";
cmd.ExecuteNonQuery();
}
DateTime endTime = DateTime.Now;
TimeSpan span = endTime - starTime;
Console.WriteLine(span.TotalMilliseconds + "毫秒");
cmd.Dispose();
}
}
执行结果:
java插入1W条数据到MSSQL2008与.net插入1W条数据到MYSQL
java插入mssql1W数据
代码
public static void main(String[] args) {
Connection conn = null;
Statement stmt = null;
try {
/*
* conn = DriverManager.getConnection(
* "jdbc:mysql://localhost:3306/myjava", "root", "123456");
*/
conn = DriverManager
.getConnection("jdbc:sqlserver://localhost:1433;"
+ "databaseName=myjava;user=sa;password=123456;");
stmt = conn.createStatement();
long starTime;
long endTime;
starTime = java.util.Calendar.getInstance().getTimeInMillis();
for (int i = 0; i < 10000; i++) {
stmt.executeUpdate("insert into users(Name,Password,Address) values('用户"
+ i + "','密码" + i + "','地址" + i + "')");
}
endTime = java.util.Calendar.getInstance().getTimeInMillis();
System.out.println((endTime - starTime) + "毫秒");
} catch (Exception e) {
System.out.println(e);
}
}
结果
.net插入1W数据到MYSQL
static void Main(string[] args)
{
string connStr = "server=localhost;user id=root; password=123456; database=myjava; pooling=false";
MySqlConnection conn = new MySqlConnection(connStr);
conn.Open();
MySqlCommand cmd = conn.CreateCommand();
DateTime starTime = DateTime.Now;
for (int i = 0; i < 10000; i++)
{
cmd.CommandText = "insert into users(Name,Password,Address) values('用户"
+ i + "','密码" + i + "','地址" + i + "')";
cmd.ExecuteNonQuery();
}
DateTime endTime = DateTime.Now;
TimeSpan span = endTime - starTime;
Console.WriteLine(span.TotalMilliseconds + "毫秒");
cmd.Dispose();
conn.Dispose();
}
结果
最后结果
java插入mysql 1w数据需要15000毫秒左右
java插入mssql2008 1w数据需要7000毫秒左右
.net插入mysql 1W 数据需要10000毫秒左右
.net插入mssql 1W数据需要5000毫秒左右