Article View: pl.comp.objects
Article #14480Re: Wyrzucenie wyjątku, czy zwrócenie null?
From: Piotr Kobzda
Date: Tue, 04 Apr 2006 16:16
Date: Tue, 04 Apr 2006 16:16
161 lines
5777 bytes
5777 bytes
Marcin 'Qrczak' Kowalczyk wrote:
>>Jest to o tyle ważne, że akurat w przypadku Javy warianty "wynikiem"
>>i "wyjątkiem" z opcją -server śmigają identycznie -- co dowodzi, że
>>tworzenie wyjątków jest w Javie jedynym dodatkowym kosztem...
>
> Hmm. Z -server pusty program wykonuje się tak samo długo jak wersja
> bez wyjątku (0.35), a wersja z wyjątkiem trochę dłużej (0.38-0.43).
> Nie umiem tego zinterpretować.
To może zobacz moje rezultaty (kod poniżej):
C:\Eclipse\Workspaces\testy\benchmarks\bin>c:\java\jdk1.5.0_06\bin\java
-Xprof -server ExcJava 50000000
..............................
ExcJava$1 t/count=0.768317764 t/10=1.92079441E7
ExcJava$2 t/count=1.809410972 t/10=4.52352743E7
ExcJava$3 t/count=1.798130212 t/10=4.49532553E7
..............................
ExcJava$1 t/count=0.696917624 t/10=1.74229406E7
ExcJava$2 t/count=1.794431416 t/10=4.48607854E7
ExcJava$3 t/count=1.786413636 t/10=4.46603409E7
Flat profile of 21.66 secs (810 total ticks): main
Interpreted + native Method
0.9% 0 + 7 java.lang.System.arraycopy
0.1% 1 + 0 ExcJava$1.run
0.1% 1 + 0 ExcJava.<clinit>
0.1% 0 + 1 java.io.FileOutputStream.writeBytes
1.2% 2 + 8 Total interpreted
Compiled + native Method
41.7% 338 + 0 ExcJava$3.run
40.4% 327 + 0 ExcJava$2.run
16.4% 133 + 0 ExcJava$1.run
98.5% 798 + 0 Total compiled
Thread-local ticks:
0.2% 2 Class loader
Flat profile of 0.01 secs (1 total ticks): DestroyJavaVM
Thread-local ticks:
100.0% 1 Blocked (of total)
Global summary of 21.68 seconds:
100.0% 812 Received ticks
0.1% 1 Compilation
0.2% 2 Class loader
piotr
--
public class ExcJava {
private static final RuntimeException exn = new RuntimeException();
static boolean test1(int x, int y) {
return x < y;
}
static void test2(int x, int y) {
if (x < y)
throw exn;
}
public static void main(String[] args) {
final int retrys = 2;
final int loops = 10;
final int m = args.length > 0
? Integer.parseInt(args[0]) : 10000000;
final int n = args.length > 1
? Integer.parseInt(args[1]) : m / 2;
abstract class Test {
volatile int count;
long t;
abstract void run();
void perform() {
long t = System.nanoTime();
run();
this.t = System.nanoTime() - t;
}
void reset() {
count = 0;
t = 0;
}
@Override
public String toString() {
return getClass().getName()
+ (count % n != 0
? " count=" + count : "")
+ " t=" + t;
}
}
Test[] tests = new Test[] {
new Test() {
void run() {
for (int i = 0; i < n; ++i) {
++count;
}
};
},
new Test() {
void run() {
for (int i = 0; i < m; ++i) {
if (test1(i, n))
++count;
}
};
},
new Test() {
void run() {
for (int i = 0; i < m; ++i) {
try {
test2(i, n);
} catch (RuntimeException x) {
++count;
}
}
};
},
};
for(int i = 0; i < retrys; ++i) {
for(int j = 0; j < loops; ++j) {
for(Test t : tests) {
t.perform();
System.out.print(".");
if (t.count % n != 0)
System.out.println(t);
}
}
System.out.println();
for(Test t : tests) {
System.out.println(t.getClass().getName()
+ " t/count=" + (double)t.t / t.count
+ " t/" + loops + "=" + (double)t.t / loops);
t.reset();
}
}
}
}
Technical Details
Message-ID:
<e0u65r$4mb$1@inews.gazeta.pl>Path:
mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.gazeta.pl!not-for-mailReferences:
<e09c3r$lg3$1@news.onet.pl> <e09f0h$cis$1@news.task.gda.pl> <e09gjn$737$1@news.onet.pl> <e0b1re$bdc$1@news.onet.pl> <e0c8eh$ur8$1@news.onet.pl> <e0cd04$ljh$1@news.task.gda.pl> <e0ced6$f7g$1@news.onet.pl> <e0dabl$1sv$1@news.task.gda.pl> <87y7ytka81.fsf <873bgukx87.fsf@qrnik.zagroda> <06040410195853@polnews.pl> <8764lpmt9q.fsf@qrnik.zagroda> <e0u0s5$cjl$1@inews.gazeta.pl> <87ek0d9xdg.fsf@qrnik.zagroda>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.gazeta.pl!not-for-mail From: Piotr Kobzda <pikob@gazeta.pl> Newsgroups: pl.comp.objects Subject: Re: Wyrzucenie wyjątku, czy zwrócenie null? Date: Tue, 04 Apr 2006 18:16:59 +0200 Organization: "Portal Gazeta.pl -> http://www.gazeta.pl" Lines: 161 Message-ID: <e0u65r$4mb$1@inews.gazeta.pl> References: <e09c3r$lg3$1@news.onet.pl> <e09f0h$cis$1@news.task.gda.pl> <e09gjn$737$1@news.onet.pl> <e0b1re$bdc$1@news.onet.pl> <e0c8eh$ur8$1@news.onet.pl> <e0cd04$ljh$1@news.task.gda.pl> <e0ced6$f7g$1@news.onet.pl> <e0dabl$1sv$1@news.task.gda.pl> <87y7ytka81.fsf <873bgukx87.fsf@qrnik.zagroda> <06040410195853@polnews.pl> <8764lpmt9q.fsf@qrnik.zagroda> <e0u0s5$cjl$1@inews.gazeta.pl> <87ek0d9xdg.fsf@qrnik.zagroda> NNTP-Posting-Host: xdsl-2179.zgora.dialog.net.pl Mime-Version: 1.0 X-Trace: inews.gazeta.pl 1144167419 4811 81.168.232.131 (4 Apr 2006 16:16:59 GMT) X-Complaints-To: usenet@agora.pl NNTP-Posting-Date: Tue, 4 Apr 2006 16:16:59 +0000 (UTC) In-Reply-To: <87ek0d9xdg.fsf@qrnik.zagroda> X-Accept-Language: pl, en-us, en X-User: pikob User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.11) Gecko/20050728 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit