Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/297.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在PHP和C中精确测量函数的运行时#_C#_Php_Image - Fatal编程技术网

C# 在PHP和C中精确测量函数的运行时#

C# 在PHP和C中精确测量函数的运行时#,c#,php,image,C#,Php,Image,一个混合的问题,我有以下PHP代码,它只是旋转和图像,以及旋转图像所需的时间: <?php ini_set("memory_limit", -1); $im = imagecreatefromjpeg("test.jpg"); $time_start = microtime(true); $rotate = imagerotate($im,90,0); $time_end = microtime(true); $execution_time = "Took ". ($time_end

一个混合的问题,我有以下PHP代码,它只是旋转和图像,以及旋转图像所需的时间:

<?php
ini_set("memory_limit", -1);
$im = imagecreatefromjpeg("test.jpg");

$time_start = microtime(true);

$rotate = imagerotate($im,90,0);

$time_end = microtime(true);
$execution_time = "Took ". ($time_end - $time_start) * 1000 ." to generate image!";

$white = imagecolorallocate($im,255,255,255);
$font = $_SERVER['DOCUMENT_ROOT']."/ppa/images/fonts/Calibri Bold.ttf";

imagettftext($rotate,15,0,20,20,$white,$font,$execution_time);

header("Content-Type: image/jpeg");
imagejpeg($rotate);

imagedestroy($im);
?>
我担心我用来计时的方法可能不匹配,我可能会得到错误的比较,是吗?…

---------------------------------------------------------------

更新了我的代码,现在我得到:

从PHP算起402.023毫秒(如果计算正确) 距离C 148毫秒#


对于旋转图像来说,这看起来很现实吗

。您正在尝试用不同的语言测量操作旋转并进行比较。但首先,你必须确保你的业务做同样的工作

在您的示例中,这并不是因为输入数据和输出数据完全不同。它是图像资源的内在表现。所以,轮换操作可以做不同的事情

但若你们在你们的测量中包括了打开和写入文件,你们就可以比较它了


另外,不要忘记jpg有压缩级别和一组不同的压缩算法。请确保您的输出文件相等(至少相似)。

您能添加一个实际问题吗?@Samuel,made很漂亮,很粗体,因此您可以看到它。首先,我不会在开始时舍入php时间戳,而是在结束时舍入。然后,您的C#代码不仅测量旋转和存储,还将其设置为一个背景图像,该图像调用一系列事件,您也在测量这些事件。你到底想测量哪一部分?要测量旋转,我现在就改变它刚刚更新了我的代码,看起来我能得到准确的比较吗?
private void rotatec_Click(object sender, EventArgs e)
    {
        Image image1 = pictureBox1.Image;
        if (image1 != null)
        {
            System.Diagnostics.Stopwatch s = System.Diagnostics.Stopwatch.StartNew();

            image1.RotateFlip(RotateFlipType.Rotate90FlipY);

            s.Stop();
            string text = "Time took: {0} ms" + s.ElapsedMilliseconds;

            pictureBox1.BackgroundImage = image1;
            image1.Save(@".\test.jpg");

            //Write to text file
            System.IO.StreamWriter file = new System.IO.StreamWriter(@".\timetook.txt");
            file.WriteLine(text);
            file.Close();
        } 
        else
        {
            MessageBox.Show("Please load an image first!");
        }
    }