我想使用并行 linq 来加快对 GetCompressionRatio 的 where 调用,但所有 Plinq 语句的语法都不同,这是我第一次使用 linq。我无法处理并行输出,但我想尽快填写查询。
static double GetCompressionRatio(string input)
{
if (string.IsNullOrEmpty(input))
throw new ArgumentNullException();
MemoryStream ms = new MemoryStream();
GZipStream gzip2 = new GZipStream(ms, CompressionMode.Compress, true);
byte[] raw = Encoding.UTF8.GetBytes(input);
gzip2.Write(raw, 0, raw.Length);
gzip2.Close();
byte[] zipped = ms.ToArray(); // as a BLOB
int startsize = raw.Length;
double percent = Convert.ToDouble(zipped.Length) / Convert.ToDouble(startsize);
return percent;
}
var query =
from sp1 in polar
...
from vp15 in polar
where GetCompressionRatio(sp1+...+vp15)>1.5
select sp1+...+vp15;
foreach (var element in query)
{
//output
}