FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Faster than java?

 
Post new topic   Reply to topic     Forum Index -> General
View previous topic :: View next topic  
Author Message
qweree



Joined: 30 May 2009
Posts: 5

PostPosted: Sat May 30, 2009 6:36 pm    Post subject: Faster than java? Reply with quote

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 Very Happy)...
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
View user's profile Send private message
michaelp



Joined: 27 Jul 2008
Posts: 114

PostPosted: Sat May 30, 2009 8:15 pm    Post subject: Reply with quote

It's a pretty simple program.
But, maybe using the lastest DMD(1.045) would yield better results?
Back to top
View user's profile Send private message
qweree



Joined: 30 May 2009
Posts: 5

PostPosted: Sun May 31, 2009 6:42 am    Post subject: Reply with quote

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
View user's profile Send private message
qweree



Joined: 30 May 2009
Posts: 5

PostPosted: Sun May 31, 2009 6:43 am    Post subject: Reply with quote

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
View user's profile Send private message
michaelp



Joined: 27 Jul 2008
Posts: 114

PostPosted: Sun May 31, 2009 7:14 am    Post subject: Reply with quote

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
View user's profile Send private message
qweree



Joined: 30 May 2009
Posts: 5

PostPosted: Sun May 31, 2009 1:25 pm    Post subject: Reply with quote

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 Wink
Back to top
View user's profile Send private message
michaelp



Joined: 27 Jul 2008
Posts: 114

PostPosted: Sun May 31, 2009 3:34 pm    Post subject: Reply with quote

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. Razz

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
View user's profile Send private message
qweree



Joined: 30 May 2009
Posts: 5

PostPosted: Sun May 31, 2009 11:55 pm    Post subject: Reply with quote

thanks a lot Very Happy ... It seems pretty easy to cross from java to D Surprised
do you know of any good tutorial to start with?
Back to top
View user's profile Send private message
michaelp



Joined: 27 Jul 2008
Posts: 114

PostPosted: Mon Jun 01, 2009 6:28 am    Post subject: Reply with quote

There is a list here:
http://prowiki.org/wiki4d/wiki.cgi?D__Tutorial

I would recommend this and this.

That first link I gave you should just about cover most D tutorials. You'll get some results on google too.
Back to top
View user's profile Send private message
csauls



Joined: 27 Mar 2004
Posts: 278

PostPosted: Wed Apr 14, 2010 5:37 pm    Post subject: Reply with quote

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. Razz

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
View user's profile Send private message AIM Address Yahoo Messenger
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> General All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group