none
Low Performance RRS feed

  • Question

  • Why this code does not take all the performance that a P4 can take?
    The CPU Usage does not take more than 40%, and this code is very slow. It´s a file that contais 100000 lines, and I use o imports each line into a database table.

    private
    void ImportarLista(string f)

    {

    progressBar1.Maximum = Convert.ToInt32(FileSystem.FileLen(f));

    SqlCommand cmd = new SqlCommand("Inserir_Peca", cnTemp);

    cmd.CommandType = CommandType.StoredProcedure;

    StreamReader sr = new StreamReader(arquivo, Encoding.ASCII, false, 512);

    string valor, line;

    cnTemp.Open();

    cmd.Parameters.Add("@codigo", SqlDbType.NVarChar);

    cmd.Parameters.Add("@alternativo", SqlDbType.NVarChar);

    cmd.Parameters.Add("@descricao", SqlDbType.NVarChar);

    cmd.Parameters.Add("@valor", SqlDbType.Money);

    cmd.Parameters.Add("@modelo", SqlDbType.NVarChar);

    cmd.Prepare();

    while (sr.Peek() >= 0)

    {

    line = sr.ReadLine();

    valor = Strings.Mid(line, 74, 11);

    cmd.Parameters["@codigo"].Value = Strings.Mid(line, 49, 18).Trim();

    cmd.Parameters["@alternativo"].Value = Strings.Mid(line, 31, 18).Trim();

    cmd.Parameters["@descricao"].Value = Strings.Mid(line, 1, 30).Trim();

    if (valor.Trim() != "0.00")

    cmd.Parameters["@valor"].Value = Strings.Mid(valor, 1, 8) + "," + Strings.Mid(valor, 10, 2);

    cmd.Parameters["@modelo"].Value = Strings.Mid(line, 96, 20).Trim();

    cmd.ExecuteNonQuery();

    progressBar1.Value += 297;

    }

    cnTemp.Close();

    }

    Monday, June 6, 2005 3:23 AM

Answers

All replies

  • My guess is that you are on a hyperthreaded P4 which will only, at max, use 50% of your CPU time for a given thread.  This is because hyperthreading is simulating two processors.  If that isn't the case, let me know and I'll try to follow up.

    See the following video and message board thread:
    http://channel9.msdn.com/ShowPost.aspx?PostID=53470
    Monday, June 6, 2005 5:03 AM
  • I know this doesn't answer your question, and it may not be workable for you, but have you looked at doing a bulk insert into a temporary table, then process the data?
    Tuesday, June 7, 2005 4:17 PM