Article View: pl.comp.lang.java
Article #141790Re: Szybkość Javy wg Horstmanna a testy...
From: jarekr
Date: Mon, 20 Oct 2008 13:25
Date: Mon, 20 Oct 2008 13:25
64 lines
2555 bytes
2555 bytes
No to już, żeby zakończyć dyskusje
wersja na 15ms
(nie używa bitset)
public class TestCode5
{
public static void main(String[] s)
{
int n = 2000000;
for (int i = 0 ; i < 10000; i++)
{
doAllCalculations(100);
}
for (int i = 0 ; i < 10; i++)
{
doAllCalculations(n);
}
doItForMe(n);
}
private static void doItForMe(int n)
{
long start = System.currentTimeMillis();
int count = doAllCalculations(n);
long end = System.currentTimeMillis();
System.out.println("Ilosc: " + count);
System.out.println((end - start) + " ms.");
}
private static int doAllCalculations(int n)
{
boolean[] b = new boolean[n+1];
int count = 0;
int i;
for (i = 2; i <= n; i++)
b[i] = true;
i = 2;
while (i * i <= n)
{
if (b[i])
{
count++;
int k = 2 * i;
while (k <= n)
{
b[k]=false;
k += i;
}
}
i++;
}
while (i <= n)
{
if (b[i])
{
count++;
}
i++;
}
return count;
}
}
Technical Details
Message-ID:
<24769ac6-ecbd-492d-b655-68805d8fde86@g25g2000prf.googlegroups.com>Path:
mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news2.icm.edu.pl!news.nask.pl!news.nask.org.pl!newsfeed00.sul.t-online.de!t-online.de!border2.nntp.dca.giganews.com!nntp.giganews.com!postnews.google.com!g25g2000prf.googlegroups.com!not-for-mailReferences:
<gdg318$g5g$1@nemesis.news.neostrada.pl> <df635ef9-4a3f-4915-be18-d2dcf7f09b9f@t18g2000prt.googlegroups.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news2.icm.edu.pl!news.nask.pl!news.nask.org.pl!newsfeed00.sul.t-online.de!t-online.de!border2.nntp.dca.giganews.com!nntp.giganews.com!postnews.google.com!g25g2000prf.googlegroups.com!not-for-mail From: jarekr <jratajski@gmail.com> Newsgroups: pl.comp.lang.java Subject: Re: Szybkość Javy wg Horstmanna a testy... Date: Mon, 20 Oct 2008 06:25:11 -0700 (PDT) Organization: http://groups.google.com Lines: 66 Message-ID: <24769ac6-ecbd-492d-b655-68805d8fde86@g25g2000prf.googlegroups.com> References: <gdg318$g5g$1@nemesis.news.neostrada.pl> <df635ef9-4a3f-4915-be18-d2dcf7f09b9f@t18g2000prt.googlegroups.com> NNTP-Posting-Host: 194.8.14.8 Mime-Version: 1.0 X-Trace: posting.google.com 1224509112 14833 127.0.0.1 (20 Oct 2008 13:25:12 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Mon, 20 Oct 2008 13:25:12 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: g25g2000prf.googlegroups.com; posting-host=194.8.14.8; posting-account=8VcG5goAAAABOIouhSJEZq2WqNug-5DI User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3 (.NET CLR 3.5.30729),gzip(gfe),gzip(gfe) Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit