편집과 2텍스트 포매터가 점차적으로 각 반복
좋아 느리게, 나는 gist.github에 내 소스의 사본을 게시 한 나는 단지 내가 해결할 수없는 하나의 느린 문제가 있습니다.
FindLine()
은 항상 -1을 반환합니다. 원인을 if 문으로 좁혔지만 이유를 알 수 없습니다. 나는 symbol과 symbolList가 모두 좋은 데이터를 전달한다는 것을 안다.
은/EDIT 내가, .csv 파일을 찾습니다 비교적 간단한 C# 프로그램이 2
가 다시 포맷, 해당 파일의 텍스트를 읽고 (그리고에로드 SQL 쿼리에서 몇 가지 정보를 포함 DataTable)에 저장하고 나중에 다른 프로그램에서 사용할 수 있도록 .tsv 파일에 저장합니다.
내 문제는 때로는 소스 .csv 파일이 10,000 줄을 넘기 때문에 프로그램이 줄을 반복하면서 느려지는 경우가 있습니다. .csv 파일이 ~ 500 줄이면 완료하는 데 약 45 초가 걸리고이 시간은 .csv 파일이 커질수록 기하 급수적으로 악화됩니다.
SQL 쿼리는 37,000+ 회선을 반환하지만 한 번만 요청되고 .csv 파일과 동일한 방식으로 정렬되므로 일반적으로 해당 파일을 찾을 수없는 경우 해당 파일을 실행하지 않습니다. 이 경우 모든 오류를 처리하고 해당 오류 텍스트를 반환합니다. 나는 그것이 감속의 원인이 아니라는 것을 99 % 확신한다.
루프 용 y 및 z는 정확히 동일해야합니다.
필자가 초기 .csv 파일에서 일부 데이터를 제거하고 예제를 게시 할 수 있으면 정말 실용적인 것을 놓치기를 바라고 있습니다.
미리 감사드립니다. 여기
내 소스이다 :using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Linq;
using System.Text;
namespace MoxySectorFormatter
{
class Program
{
static void Main(string[] args)
{
DataTable resultTable = new DataTable();
double curLine = 1;
double numLines = 0;
string ExportPath = @"***PATH***\***OUTFILE***.tsv";
string ImportPath = @"***PATH***\***INFILE***.csv";
string NewText = "SECURITY\r\n";
string OrigText = "";
string QueryString = "SELECT DISTINCT UPPER(MP.Symbol) AS Symbol, LOWER(MP.SecType) AS SecType, MBI.Status FROM MoxySecMaster AS MP LEFT JOIN MoxyBondInfo AS MBI ON MP.Symbol = MBI.Symbol AND MP.SecType = MBI.SecType WHERE MP.SecType <> 'caus' AND MP.SecType IS NOT NULL AND MP.Symbol IS NOT NULL ORDER BY Symbol ASC;";
SqlConnection MoxyConn = new SqlConnection("server=***;database=***;user id=***;password=***");
SqlDataAdapter adapter = new SqlDataAdapter(QueryString, MoxyConn);
MoxyConn.Open();
Console.Write("Importing source file from \"{0}\".", ImportPath);
OrigText = File.ReadAllText(ImportPath);
OrigText = OrigText.Substring(OrigText.IndexOf("\r\n", 0) + 2);
Console.WriteLine("\rImporting source file from \"{0}\". Done!", ImportPath);
Console.Write("Scanning source report.");
for (int loop = 0; loop < OrigText.Length; loop++)
{
if (OrigText[loop] == '\r')
numLines++;
}
Console.WriteLine("\rScanning source report. Done!");
Console.Write("Downloading SecType information.");
resultTable = new DataTable();
adapter.Fill(resultTable);
MoxyConn.Close();
Console.WriteLine("\rDownloading SecType information. Done!");
for (int lcv = 0; lcv < numLines; lcv++)
{
int foundSpot = -1;
int nextStart = 0;
Console.Write("\rGenerating new file... {0}/{1} ({2}%) ", curLine, numLines, System.Math.Round(((curLine/numLines) * 100), 2));
for (int vcl = 0; vcl < resultTable.Rows.Count; vcl++)
{
if (resultTable.Rows[vcl][0].ToString() == OrigText.Substring(0, OrigText.IndexOf(",", 0)).ToUpper() && resultTable.Rows[vcl][1].ToString().Length > 0)
{
foundSpot = vcl;
break;
}
}
if (foundSpot != -1 && foundSpot < resultTable.Rows.Count)
{
NewText += resultTable.Rows[foundSpot][1].ToString();
NewText += "\t";
NewText += OrigText.Substring(nextStart, (OrigText.IndexOf(",", nextStart) - nextStart));
NewText += "\t";
nextStart = OrigText.IndexOf(",", nextStart) + 1;
for (int y = 0; y < 142; y++)
NewText += "\t";
if(resultTable.Rows[foundSpot][2].ToString() == "r")
NewText += @"PRE/ETM";
else if (OrigText.Substring(nextStart, (OrigText.IndexOf(",", nextStart) - nextStart)) == "Municipals")
{
NewText += "Muni - ";
nextStart = OrigText.IndexOf(",", nextStart) + 1;
if (OrigText.Substring(nextStart, (OrigText.IndexOf(",", nextStart) - nextStart)).Length > 0)
NewText += OrigText.Substring(nextStart, (OrigText.IndexOf(",", nextStart) - nextStart));
else
NewText += "(Orphan)";
}
else if (OrigText.Substring(nextStart, (OrigText.IndexOf(",", nextStart) - nextStart)) == "Corporates")
{
NewText += "Corporate - ";
nextStart = OrigText.IndexOf(",", nextStart) + 1;
nextStart = OrigText.IndexOf(",", nextStart) + 1;
if (OrigText.Substring(nextStart, (OrigText.IndexOf("\r\n", nextStart) - nextStart)).Length > 0)
NewText += OrigText.Substring(nextStart, (OrigText.IndexOf("\r\n", nextStart) - nextStart));
else
NewText += "(Unknown)";
}
else
NewText += OrigText.Substring(nextStart, (OrigText.IndexOf(",", nextStart) - nextStart));
for (int z = 0; z < 17; z++)
NewText += "\t";
NewText += "\r\n";
resultTable.Rows.RemoveAt(foundSpot);
}
else
Console.WriteLine("\r Omitting {0}: Missing Symbol or SecType.", OrigText.Substring(nextStart, (OrigText.IndexOf(",", nextStart) - nextStart)));
OrigText = OrigText.Substring(OrigText.IndexOf("\r\n", 0) + 2);
curLine++;
}
Console.Write("Exporting file to \"{0}\".", ExportPath);
File.WriteAllText(ExportPath, NewText);
Console.WriteLine("\rExporting file to \"{0}\". Done!\nPress any key to exit.", ExportPath);
Console.ReadLine();
}
}
}
나는 이것을 매우 간단한 프로그램이라고 부르지 않을 것입니다. 긴급 리팩터링을 위해 우는 코드라고 할 수 있습니다. –
lol 저는 한달 동안 C#을 사용해 왔습니다. 그게 무슨 뜻이야? 나는 결코 haha에 대해 들어 본 적이없는 기술을 사용하여 처음부터 시작하는 것을 포함하여 절대적으로 어떤 제안도 할 수 있습니다. – newuser
특히'StringBuilder'를 사용합니다. –