Recent Changes - Search:

Oktatás

* Programozás 1
  + feladatsor
  + GitHub oldal

* Szkriptnyelvek
  + feladatsor
  + quick link

Teaching

* Programming 1 (BI)
  ◇ exercises
  ◇ quick link

teaching assets


Félévek

* 2025/26/2
* archívum


Linkek

* kalendárium
   - munkaszüneti napok '20
* tételsorok
* jegyzetek
* szakdolgozat / PhD
* ösztöndíjak
* certificates
* C lang.
* C++
* C#
* Clojure
* D lang.
* Java
* Nim
* Nim2
* Scala


[ edit | logout ]
[ sandbox | passwd ]

Run a program without explicitly compiling it

The command "nim r prg.nim" does the following:

  • Compiles the program and executes it.
  • The EXE is cached (under Linux, it'll be here: $HOME/.cache/nim/…)
  • If you want to execute it again with "nim r prg.nim", it'll run the cached EXE. The program is not re-compiled.
  • It's intelligent. If you modify the source code, it'll notice that and the program will be re-compiled.

However, as I noticed, it executes the cached EXE quite slowly. It takes about 100 msec on my PC.

Example:

$ nim r prg.nim
Hint: used config file '/home/jabba/.choosenim/toolchains/nim-2.2.8/config/nim.cfg' [Conf]
Hint: used config file '/home/jabba/.choosenim/toolchains/nim-2.2.8/config/config.nims' [Conf]
..........................................................................................
/tmp/send/prg.nim(4, 8) Warning: imported and not used: 'strutils' [UnusedImport]
/tmp/send/prg.nim(5, 8) Warning: imported and not used: 'strformat' [UnusedImport]
/tmp/send/prg.nim(6, 8) Warning: imported and not used: 'sequtils' [UnusedImport]
CC: system/exceptions.nim
CC: std/private/digitsutils.nim
CC: system/dollars.nim
CC: system.nim
CC: prg.nim
Hint:  [Link]
Hint: mm: orc; threads: on; opt: none (DEBUG BUILD, `-d:release` generates faster code)
45286 lines; 0.674s; 59.059MiB peakmem; proj: /tmp/send/prg.nim; out: 
/home/jabba/.cache/nim/prg_d/prg_2E35874E36BC0A3365C1006F19810C4C4978E67C [SuccessX]
Hint: /home/jabba/.cache/nim/prg_d/prg_2E35874E36BC0A3365C1006F19810C4C4978E67C [Exec]
hello

$ nim r prg.nim
Hint: used config file '/home/jabba/.choosenim/toolchains/nim-2.2.8/config/nim.cfg' [Conf]
Hint: used config file '/home/jabba/.choosenim/toolchains/nim-2.2.8/config/config.nims' [Conf]
Hint: mm: orc; threads: on; opt: none (DEBUG BUILD, `-d:release` generates faster code)
10787 lines; 0.020s; 10.555MiB peakmem; proj: /tmp/send/prg.nim; out: 
/home/jabba/.cache/nim/prg_d/prg_2E35874E36BC0A3365C1006F19810C4C4978E67C [SuccessX]
Hint: /home/jabba/.cache/nim/prg_d/prg_2E35874E36BC0A3365C1006F19810C4C4978E67C [Exec]
hello

Here, "hello" is the output of the simple program. When "nim r prg.nim" is executed for the first time, the program is compiled first and then executed. When "nim r prg.nim" is executed for the second time, the program is not compiled, just the cached EXE is executed.

You can also suppress the info lines:

$ time nim r  --hints:off --warnings:off prg.nim
hello (534 msec)

$ time nim r  --hints:off --warnings:off prg.nim
hello (100 msec)

As I mentioned earlier, the cached EXE is executed quite slowly. That 100 msec is a lot. Let's compile the program and check how fast the EXE starts:

$ nim c prg.nim

$ time ./prg
hello (2.33 msec)

That's 43x faster. I have a solution for this problem, see here.

Cloud City

  

Blogjaim, hobbi projektjeim

* The Ubuntu Incident
* Python Adventures
* @GitHub
* heroku
* extra
* haladó Python
* YouTube listák


Debrecen | la France


[ edit ]

Edit - History - Print *** Report - Recent Changes - Search
Page last modified on 2026 March 19, 20:54