Try putting it in a function: http://docs.julialang.org/en/release-0.3/manual/performance-tips/
On Tue, Jan 6, 2015 at 8:38 PM, Rodolfo Santana <santana9...@gmail.com> wrote: > I am showing a Julia code below. The goal is just to calculate x in the > end of the code and calculate how long it takes Julia to calculate x. In > Julia, it takes about 1e-3 seconds. This is very surprising to me. I wrote > the same code in Matlab and it only takes 2e-6 seconds and in Python it > takes 5e-6 seconds. Is there any way to speed up this calculation in Julia? > I couldn't find the answer on the internet, any help would be much > appreciated. > > Sincerely, > -Rodolfo > > > > > # Electron mass in grams > m_e = 9.1094e-28 > # Speed of light in cm/sec > c = 2.9979e10 > > # Electron momentum direction in Cartesian coordinates > v10elec = 1.0/sqrt(2.0) > v20elec = -1.0/sqrt(3.0) > v30elec = 1.0/sqrt(6.0) > > # Photon momentum direction in Cartesian coordinates > omega_one_phot = -1.0/sqrt(3.0) > omega_two_phot = 1.0/sqrt(4.0) > omega_three_phot = sqrt(5.0/12.0) > > # Dimensionless electron speed and Lorentz factor > beta_e = 0.98 ; > gamma_e = 1.0/sqrt(1-beta_e*beta_e) > > # Photon energy in ergs > E_phot_comv = 1.6022e-9 > > # Angle between electron and photon momentum > mu = v10elec*omega_one_phot + v20elec*omega_two_phot + > v30elec*omega_three_phot > > # Dimensionless energy of photon in electron rest frame > tic() > x = (2.0*gamma_e*E_phot_comv*(1-mu*beta_e))/(m_e*c*c) > toc() > >