Click here to Skip to main content
15,886,362 members
Articles / Programming Languages / Java

Operation Performance Evaluation

Rate me:
Please Sign up or sign in to vote.
4.91/5 (62 votes)
18 Jan 2012CPOL23 min read 103.2K   1.7K   89  
Investigating the cost of an operation in cycles within a real world, i.e., no peak, performance measurement of C#, C++, Java, Fortran and JavaScript
      PROGRAM MEASUREMENT
      INTEGER s
      INTEGER A (100000), B (100000), C (100000)
      INTEGER r
      INTEGER i, j
      REAL TIMEARRAY (2)
      REAL DELAPSE
      CALL srand(0)
      s = 100000
      r = 10000

C	Idea for Timing was taken from	(gets relative time)
C	http://www.phys.ufl.edu/~coldwell/Progdet/UNIX%20FORTRAN%20Timing.htm
C	Another approach was found at   (gets absolute time)
C	http://pc.freeshell.org/comp/fortran

C	-----------
C	------
C	THIS IS A BASIC PORT OF THE C#-PROGRAM WRITTEN BY SIMON MAGES
C	THIS PORT AIMS TO BE AS CLOSE AS POSSIBLE TO THE C# PROGRAM
C	PORT DONE BY FLORIAN RAPPL, 2011
C	------
C	-----------

C	HERE WE GET THE TIME IN SECONDS --- i.e. we have to multiply with Ticks / s
C	The Ticks / s is given by Frequency [ Cycles / s ] * 1000 [ Ticks / Cycle ]
	  
      do i = 1, s
        A(i) = 10 * rand(0) + 1
        B(i) = 10 * rand(0) + 1
      enddo

      DELAPSE=DTIME(TIMEARRAY)
      do j = 1, r
        do i = 1, s
          C(i) = A(i) + B(i)
        enddo
      enddo

      DELAPSE=DTIME(TIMEARRAY)
      WRITE (*,*) '+:    ', DELAPSE
      DELAPSE=DTIME(TIMEARRAY)
      do j = 1, r
        do i = 1, s
          C(i) = A(i) - B(i)
        enddo
      enddo
 
      DELAPSE=DTIME(TIMEARRAY)
      WRITE (*,*) '-:    ', DELAPSE
      DELAPSE=DTIME(TIMEARRAY)
      do j = 1, r
        do i = 1, s
          C(i) = A(i) * B(i)
        enddo
      enddo

      DELAPSE=DTIME(TIMEARRAY)
      WRITE (*,*) '*:    ', DELAPSE
      DELAPSE=DTIME(TIMEARRAY)
	  
      do j = 1, r
        do i = 1, s
          C(i) = A(i) / B(i)
        enddo
      enddo
   
      DELAPSE=DTIME(TIMEARRAY)
      WRITE (*,*) '/:    ', DELAPSE
      DELAPSE=DTIME(TIMEARRAY)
  	  
      do j = 1, r
        do i = 1, s
          C(i) = MOD(A(i), B(i))
        enddo
      enddo
   
      DELAPSE=DTIME(TIMEARRAY)
      WRITE (*,*) '%:    ', DELAPSE
      DELAPSE=DTIME(TIMEARRAY)
  	  
      do j = 1, r
        do i = 1, s
          C(i) = A(i) / B(i) + MOD(A(i), B(i))
        enddo
      enddo
   
      DELAPSE=DTIME(TIMEARRAY)
      WRITE (*,*) '/ + %:    ', DELAPSE
      DELAPSE=DTIME(TIMEARRAY)
   
      do j = 1, r
        do i = 1, s
          C(i) = A(i) / B(i)
          C(i) = C(i) + A(i) - C(i) * B(i)
        enddo
      enddo

      DELAPSE=DTIME(TIMEARRAY)
      WRITE (*,*) '/ + -*:    ', DELAPSE	
      END PROGRAM

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Chief Technology Officer
Germany Germany
Florian lives in Munich, Germany. He started his programming career with Perl. After programming C/C++ for some years he discovered his favorite programming language C#. He did work at Siemens as a programmer until he decided to study Physics.

During his studies he worked as an IT consultant for various companies. After graduating with a PhD in theoretical particle Physics he is working as a senior technical consultant in the field of home automation and IoT.

Florian has been giving lectures in C#, HTML5 with CSS3 and JavaScript, software design, and other topics. He is regularly giving talks at user groups, conferences, and companies. He is actively contributing to open-source projects. Florian is the maintainer of AngleSharp, a completely managed browser engine.

Comments and Discussions