<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>waimv.com &#187; c</title>
	<atom:link href="http://www.waimv.com/tag/c/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.waimv.com</link>
	<description></description>
	<lastBuildDate>Fri, 09 Nov 2018 10:41:46 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>c java php 语言性能对比</title>
		<link>http://www.waimv.com/php/278/</link>
		<comments>http://www.waimv.com/php/278/#comments</comments>
		<pubDate>Mon, 19 Aug 2013 07:37:21 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[c]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.szpian.com/?p=278</guid>
		<description><![CDATA[同一台服务器测试 C      0.04 秒 Java   0.21 秒 PHP  2.06  秒 由此可算出 C 是 java性能的5倍，Java 是 PHP 性能的10倍 C #include &#60;stdio.h&#62; #include &#60;sys/time.h&#62; #define BAILOUT 16 #define MAX_ITERATIONS 1000 int mandelbrot(double x, double y) { double cr = y - 0.5; double ci = x; double zi = 0.0; double zr = 0.0; [...]]]></description>
			<content:encoded><![CDATA[<p>同一台服务器测试</p>
<p>C      0.04 秒</p>
<p>Java   0.21 秒</p>
<p>PHP  2.06  秒</p>
<p>由此可算出 C 是 java性能的5倍，Java 是 PHP 性能的10倍</p>
<p><strong>C</strong></p>
<pre class="brush: cpp">#include &lt;stdio.h&gt;
#include &lt;sys/time.h&gt;

#define BAILOUT 16
#define MAX_ITERATIONS 1000

int mandelbrot(double x, double y)
{
	double cr = y - 0.5;
	double ci = x;
	double zi = 0.0;
	double zr = 0.0;
	int i = 0;

	while(1) {
		i ++;
		double temp = zr * zi;
		double zr2 = zr * zr;
		double zi2 = zi * zi;
		zr = zr2 - zi2 + cr;
		zi = temp + temp + ci;
		if (zi2 + zr2 &gt; BAILOUT)
			return i;
		if (i &gt; MAX_ITERATIONS)
			return 0;
	}

}

int main (int argc, const char * argv[]) {
	struct timeval aTv;
	gettimeofday(&amp;aTv, NULL);
	long init_time = aTv.tv_sec;
	long init_usec = aTv.tv_usec;

	int x,y;
	for (y = -39; y &lt; 39; y++) {
		printf("\n");
		for (x = -39; x &lt; 39; x++) {
			int i = mandelbrot(x/40.0, y/40.0);
			if (i==0)
				printf("*");
			else
				printf(" ");
		}
	}
	printf ("\n");

	gettimeofday(&amp;aTv,NULL);
	double query_time = (aTv.tv_sec - init_time) + (double)(aTv.tv_usec - init_usec)/1000000.0;
	printf ("C Elapsed %0.2f\n", query_time);
    return 0;
}</pre>
<p><strong>Java</strong></p>
<pre class="brush: java">import java.util.*;

class Mandelbrot
{
	static int BAILOUT = 16;
	static int MAX_ITERATIONS = 1000;

	private static int iterate(float x, float y)
	{
		float cr = y-0.5f;
		float ci = x;
		float zi = 0.0f;
		float zr = 0.0f;
		int i = 0;
		while (true) {
			i++;
			float temp = zr * zi;
			float zr2 = zr * zr;
			float zi2 = zi * zi;
			zr = zr2 - zi2 + cr;
			zi = temp + temp + ci;
			if (zi2 + zr2 &gt; BAILOUT)
				return i;
			if (i &gt; MAX_ITERATIONS)
				return 0;
		}
	}

	public static void main(String args[])
	{
		Date d1 = new Date();
		int x,y;
		for (y = -39; y &lt; 39; y++) {
			System.out.print("\n");
			for (x = -39; x &lt; 39; x++) {
				if (iterate(x/40.0f,y/40.0f) == 0)
					System.out.print("*");
				else
					System.out.print(" ");

			}
		}
		Date d2 = new Date();
		long diff = d2.getTime() - d1.getTime();
		System.out.println("\nJava Elapsed " + diff/1000.0f);

	}
}</pre>
<p><strong>PHP</strong></p>
<pre class="brush: php">&lt;?php
define("BAILOUT",16);
define("MAX_ITERATIONS",1000);

class Mandelbrot
{

	function Mandelbrot()
	{
		$d1 = microtime(1);
		for ($y = -39; $y &lt; 39; $y++) {
			echo("\n");
			for ($x = -39; $x &lt; 39; $x++) {
				if ($this-&gt;iterate($x/40.0,$y/40.0) == 0)
					echo("*");
				else
					echo(" ");

			}
		}
		$d2 = microtime(1);
		$diff = $d2 - $d1;
		printf("\nPHP Elapsed %0.2f", $diff);
	}

	function iterate($x,$y)
	{
		$cr = $y-0.5;
		$ci = $x;
		$zi = 0.0;
		$zr = 0.0;
		$i = 0;
		while (true) {
			$i++;
			$temp = $zr * $zi;
			$zr2 = $zr * $zr;
			$zi2 = $zi * $zi;
			$zr = $zr2 - $zi2 + $cr;
			$zi = $temp + $temp + $ci;
			if ($zi2 + $zr2 &gt; BAILOUT)
				return $i;
			if ($i &gt; MAX_ITERATIONS)
				return 0;
		}

	}

}

$m = new Mandelbrot();
?&gt;</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.waimv.com/php/278/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
