2016-09-16 16 views
0

私は、プロジェクトにクエリをサーバーに表示する必要があります。 複数のストップウォッチを使用している:機能性能(タイマー)このタイマの合計時間DB応答のストップウォッチの合計時間の問題

1)Webサービスの応答を(TechDoctimer)

2)(dbTimer)

3) 「最大のもの」であり、他のすべてのタイマーはそのパフォーマンスの中に入れ子になっています。

その結果、私は、合計うちはtimer少ないしでしょう(デシベルと技術文書ストップウオッチから)2つの番号を取得する必要がありますが、私はこのような何かを得る:

Serverの合計応答時間を:1.351(秒)

技術文書の総応答時間:1.215(秒)

データベースの価格の合計応答時間:0.67(秒)

ご覧のとおり、TechDoc + Database >サーバーの合計応答時間。 Visual Studioだけではスレッドを実行できない場合、どのように発生するのか理解できません。

public static FullModel GetDetailList(string article) 
    { 
     Stopwatch timer = new Stopwatch(); 
     timer.Start(); 
     Stopwatch dbTimer = new Stopwatch(); 
     Stopwatch TechDoctimer = new Stopwatch(); 

     var db = new TecAllianceEntities(); 
     FullModel model = new FullModel(); 
     model.details = new List<DetailModel>(); 
     List<string> listOfNo = new List<string>(); 
     int articleId; 

     TechDoctimer.Start(); 
     List<int> listOfIdsFound = RequestDetailIdByArticle(article); 
     TechDoctimer.Stop(); 


     foreach (var item in listOfIdsFound) 
     { 
      DetailModel detail = new DetailModel(); 
      detail.oeNumberList = new List<OENumberModel>(); 
      detail.documents = new List<DocumentModel>(); 
      detail.attributeList = new List<AttributeModel>(); 

      articleId = item; 

      TechDoctimer.Start(); 
      string resultFromRequestDetailById = TecAllianceResponce.RequestDetailByIds(articleId); 
      TechDoctimer.Stop(); 

      var result = TecAllianceResponce.GetSorted(resultFromRequestDetailById); 

      for (int i = 0; i < result.Count; i++) 
      { 
       switch (result[i]) 
       { 
        case "articleId": 
         detail.articleId = Int32.Parse(result[i + 1]); 
         break; 

        case "articleName": 
         detail.articleName = result[i + 1]; 
         break; 

        case "articleNo": 
         detail.articleNo = result[i + 1]; 
         listOfNo.Add(result[i + 1]); 
         break; 

        case "articleStateName": 
         detail.articleStateName = result[i + 1]; 
         break; 

        case "brandName": 
         if (result[i - 2] == "articleStateName") 
          detail.brandName = result[i + 1]; 
         break; 

        case "packingUnit": 
         detail.packingUnit = Int32.Parse(result[i + 1]); 
         break; 

        case "quantityPerPackingUnit": 
         detail.quantityPerPackingUnit = Int32.Parse(result[i + 1]); 
         break; 

        case "docId": 
         detail.hasDocuments = result[i + 1] != "0" ? true : false; 
         DocumentModel newDoc = new DocumentModel() 
         { 
          docId = Int32.Parse(result[i + 1]), 
          docFileName = result[i - 1], 
          docTypeName = result[i + 5] 
         }; 
         newDoc.docURL = "http://webservicepilot.tecdoc.net/pegasus-3-0/documents/367/" + newDoc.docId + "/" + 0; 
         detail.documents.Add(newDoc); 
         break; 

        case "oeNumber": 
         detail.hasDocuments = result[i + 1] != "0" ? true : false; 
         OENumberModel newOE = new OENumberModel() 
         { 
          brandName = result[i - 1], 
          oeNumber = result[i + 1] 
         }; 
         detail.oeNumberList.Add(newOE); 
         break; 

        case "attrName": 
         AttributeModel newAttr = new AttributeModel() 
         { 
          attrName = result[i + 1] 
         }; 
         for (int j = i; j <= i + 12; j++) 
         { 
          if (result[j] == "attrValue") newAttr.attrValue = result[j + 1]; 
          if (result[j] == "attrUnit") newAttr.attrUnit = result[j + 1]; 
         } 
         if (newAttr.attrUnit == null) newAttr.attrUnit = ""; 
         detail.attributeList.Add(newAttr); 
         break; 
       } 
      } 
      model.details.Add(detail); 
     } 

     dbTimer.Start(); 
     if (listOfNo.Any()) 
     { 
      var queryPrices = db.PRECES.Where(p => listOfNo.Contains(p.RAZOTAJA_KODI)).Select(p => new { p.RAZOTAJA_KODI, p.REALIZ_CENA }).ToList(); 
      dbTimer.Stop(); 
      foreach (var item in model.details) 
      { 
       try 
       { 
        item.price = queryPrices.Where(q => q.RAZOTAJA_KODI == item.articleNo).Select(q => q.REALIZ_CENA).First(); 
       } 
       catch 
       { 
        item.price = 0; 
       } 
      } 
     } 
     else 
     { 
      dbTimer.Stop(); 
     } 

     timer.Stop(); 
     TimeSpan timeTaken = timer.Elapsed; 
     TimeSpan TechDocUsageTime = TechDoctimer.Elapsed; 
     TimeSpan dbRequestTime = dbTimer.Elapsed; 

     model.dbTimeTaken = dbRequestTime.Seconds + "." + dbRequestTime.Milliseconds; 
     model.TimeTaken = timeTaken.Seconds + "." + timeTaken.Milliseconds; 
     model.TimeTechDoc = TechDocUsageTime.Seconds + "." + TechDocUsageTime.Milliseconds; 

     return model; 
    } 
} 
+2

'model.dbTimeTaken = dbRequestTime.TotalSeconds + "を使用してください。" + dbRequestTime.Milliseconds 'です。プロパティ秒には現在の分の秒のみが含まれます。だから1分以上かかると間違った結果になります。 –

+1

まさに私が考えていたものです。 SecondsとMillisecondsを組み合わせるのではなく、TimeSpanのTotalSecondsプロパティを使用してください。また、ドキュメントを確認してください。https://msdn.microsoft.com/en-us/library/system.timespan.seconds(v=vs.110).aspx –

+0

5秒以下、通常は約2〜3秒かかります。 – GeekyNuns

答えて

1

あなたは、なぜあなただ​​けのTimeSpan.ToString()出力を使用していない文字列に結果を保存していると見て:ここでは

は私の関数のコードですか?