ama*_*eur 1 c# optimization performance base64 data-uri
我使用以下方法将图像转换为base64字符串:
FileStream fs = new FileStream(imagePath, FileMode.Open,FileAccess.Read);
byte[] filebytes = new byte[fs.Length];
fs.Read(filebytes, 0, Convert.ToInt32(fs.Length));
return Convert.ToBase64String(filebytes, Base64FormattingOptions.InsertLineBreaks);
Run Code Online (Sandbox Code Playgroud)
对于每个页面加载,此方法在运行时运行多次.我担心我网站上的性能会受到影响.
我知道它会影响性能,但会对它产生重大影响吗?
通常,确定性能影响的最佳方法是测量它.看起来这可能会导致一些CPU使用率,内存开销和一些磁盘IO,所以这些是我要注意的问题.使用负载测试工具来模拟实际数量的并发用户,并查看会发生什么.
对于它的价值,如果这些图像始终是相同的,那么您可以缓存此方法的输出.
| 归档时间: |
|
| 查看次数: |
2699 次 |
| 最近记录: |