View previous topic :: View next topic |
Author |
Message |
qweree
Joined: 30 May 2009 Posts: 5
|
Posted: Sat May 30, 2009 6:36 pm Post subject: Faster than java? |
|
|
Hi!
First of all, I'm new to D... but i heard its speed can compare to c++'s.
I installed dmd 1.030 or something like that and ran this code:
Code: |
import std.stdio;
void main(string[] args)
{
int st = 0;
string neki = "lala";
for(int i = 0; i < 140000; i++) {
for(int j = 0; j < 140000; j++) {
st++;
}
}
writefln("%d",st);
writefln("\n%s",neki);
}
|
String is there just for the test if it works (and yes i noticed it does )...
Anyway... the time it takes to run this when compiled with (dmd -inline -release filename.d)
is the same as that of java (I wrote the same thing in java).
Am I doing something wrong or are loops equally fast? where is D faster?
Thanks! |
|
Back to top |
|
|
michaelp
Joined: 27 Jul 2008 Posts: 114
|
Posted: Sat May 30, 2009 8:15 pm Post subject: |
|
|
It's a pretty simple program.
But, maybe using the lastest DMD(1.045) would yield better results? |
|
Back to top |
|
|
qweree
Joined: 30 May 2009 Posts: 5
|
Posted: Sun May 31, 2009 6:42 am Post subject: |
|
|
Edit: sry double post :s
Last edited by qweree on Sun May 31, 2009 6:44 am; edited 1 time in total |
|
Back to top |
|
|
qweree
Joined: 30 May 2009 Posts: 5
|
Posted: Sun May 31, 2009 6:43 am Post subject: |
|
|
I installed dmd 1.045 (over dmd 1.030) and when i compile i get some error that it cant find object.d or something like that :\ Anyone knows how to fix this?
thanks |
|
Back to top |
|
|
michaelp
Joined: 27 Jul 2008 Posts: 114
|
Posted: Sun May 31, 2009 7:14 am Post subject: |
|
|
Okay, first thing is, assuming you don't have any important stuff in your DMD installations, just delete all of it.
Then, extract dmd1.045 to where ever you want to install it. (C:\dmd)
Add C:\dmd\windows\bin to your path. (Use google if you don't know how to do that)
The reason is that in a (somewhat) recent dmd release, the bin and lib folders were moved to linux/, windows/, and mac/.
Also, also add -O (that is an o, not a zero) when you compile, so it's:
Code: | dmd -release -O -inline somefile.d |
|
|
Back to top |
|
|
qweree
Joined: 30 May 2009 Posts: 5
|
Posted: Sun May 31, 2009 1:25 pm Post subject: |
|
|
thanks a lot! i works now... however im facing some problems with compiling the folowing source:
Code: |
import std.stdio;
public class DiGraph {
public int[][] v;
this(int n) {
v = new int[n][n];
}
//print 2D array
public void izpisi2() {
int i,j;
for(i = 0; i < v.length; i++) {
for(j = 0; j < v[i].length; j++)
writef("%d ", v[i][j]);
writefln();
}
}
}
//-------------------main---------------------
int main() {
DiGraph miza = new DiGraph(3);
miza.v[0][1] = 1;
miza.v[2][2] = 2;
miza.izpisi2();
return 0;
}
|
i get the following errors:
DiGraph.d(11): Error: Integer constant expression expected instead of n
DiGraph.d(11): Error: Integer constant expression expected instead of cast(uint)
n
DiGraph.d(11): Error: Integer constant expression expected instead of cast(uint)
n
DiGraph.d(11): Error: Integer constant expression expected instead of cast(uint)
n
DiGraph.d(11): Error: cannot implicitly convert expression (new int[cast(uint)n]
[](cast(uint)n)) of type int[cast(uint)n][] to int[][]
is there a way i can do things like this (im used to java), or will i always have to tell whats the first dimension like public int[3][] v; ?
thanks again |
|
Back to top |
|
|
michaelp
Joined: 27 Jul 2008 Posts: 114
|
Posted: Sun May 31, 2009 3:34 pm Post subject: |
|
|
Code: | this(int n) {
v.length = n;
for( int i = 0; i < n; i++ )
v[i].length = n;
} |
That compiles for me. Will explain it later, I need to go somewhere.
edit: Okay. Basically, that means go through every array in v, and make it the length of n. I'm not sure if this is the best way to do it, but it compiles and runs okay. |
|
Back to top |
|
|
qweree
Joined: 30 May 2009 Posts: 5
|
Posted: Sun May 31, 2009 11:55 pm Post subject: |
|
|
thanks a lot ... It seems pretty easy to cross from java to D
do you know of any good tutorial to start with? |
|
Back to top |
|
|
michaelp
Joined: 27 Jul 2008 Posts: 114
|
|
Back to top |
|
|
csauls
Joined: 27 Mar 2004 Posts: 278
|
Posted: Wed Apr 14, 2010 5:37 pm Post subject: |
|
|
michaelp wrote: | Code: | this(int n) {
v.length = n;
for( int i = 0; i < n; i++ )
v[i].length = n;
} |
That compiles for me. Will explain it later, I need to go somewhere.
edit: Okay. Basically, that means go through every array in v, and make it the length of n. I'm not sure if this is the best way to do it, but it compiles and runs okay. |
That works, but its better to just use Code: | new int[][]( n, n ) |
Unless something changed recently that killed that. _________________ Chris Nicholson-Sauls |
|
Back to top |
|
|
|