This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
notes:comporg:projects:pnc1 [2018/01/31 17:56] – [Project: IMPLEMENTATIONS AND OPTIMIZATIONS - PRIME NUMBER COMPUTATION (pnc1)] kbeykirc | notes:comporg:projects:pnc1 [2018/02/06 13:41] (current) – [Project: IMPLEMENTATIONS AND OPTIMIZATIONS - PRIME NUMBER COMPUTATION (pnc1)] bstrong2 | ||
---|---|---|---|
Line 16: | Line 16: | ||
interpreter ${0}.ext ${*} | interpreter ${0}.ext ${*} | ||
+ | exit 0 | ||
+ | </ | ||
+ | |||
+ | for example: | ||
+ | < | ||
+ | #! /bin/bash | ||
+ | |||
+ | python ${0}.py ${*} | ||
exit 0 | exit 0 | ||
</ | </ | ||
Line 61: | Line 69: | ||
See how it runs with **pncrun** for each compiler. \\ | See how it runs with **pncrun** for each compiler. \\ | ||
+ | |||
+ | **Command Line Arguments: | ||
+ | Just a friendly reminder that when command line arguments are passed they are usually (I don't know of any cases when they aren't actually) passed as strings. Make sure to cast it from a string to whichever data type it is supposed to be. | ||
+ | |||
+ | |||
+ | **Go** \\ | ||
+ | < | ||
+ | |||
+ | **Lua** \\ | ||
+ | < | ||
+ | |||
+ | **Python3**\\ | ||
+ | I don't know for sure if this works for Python2 | ||
+ | < | ||
+ | |||
+ | |||
**To compile a go program:** \\ | **To compile a go program:** \\ | ||
Line 138: | Line 162: | ||
require " | require " | ||
- | time = Benchmark.realtime.do | + | time = Benchmark.realtime do |
// insert prime calculation code here | // insert prime calculation code here | ||
Line 177: | Line 201: | ||
Code modeled after the first answer here: https:// | Code modeled after the first answer here: https:// | ||
+ | To do it in Java: | ||
+ | < | ||
+ | long startTime = System.nanoTime(); | ||
+ | .....your program.... | ||
+ | long endTime | ||
+ | long totalTime = endTime - startTime; | ||
+ | System.out.println(totalTime); | ||
+ | </ | ||
+ | (You can change the output format as this will give you nano seconds) | ||
+ | Or if you don't want to deal with nanoseconds you can use " | ||
+ | |||
+ | |||
+ | **How to compile and run a java program in the terminal**\\ | ||
+ | |||
+ | Because compiling a java program will cause memory issues, some boundaries are needed to compile the program: | ||
+ | < | ||
+ | javac -J-XX: | ||
+ | -J-XX: | ||
+ | </ | ||
+ | To run the program: | ||
+ | < | ||
+ | export CLASSPATH=${HOME}/ | ||
+ | |||
+ | java -XX: | ||
+ | </ | ||
+ | |||
+ | |||
+ | |||
+ | To display the time in Bash: | ||
+ | < | ||
+ | startTime=`date +%s%N` | ||
+ | |||
+ | -Pnc1 code- | ||
+ | |||
+ | endTime=`date +%s%N` | ||
+ | |||
+ | totalTime=`bc <<< | ||
+ | totalTime=`bc <<< | ||
+ | echo " | ||
+ | </ | ||
+ | |||
+ | |||
+ | JavaScript: | ||
+ | |||
+ | The wrapper is as follows: | ||
+ | |||
+ | < | ||
+ | #!/bin/bash | ||
+ | ## | ||
+ | ## Wrapper for nodejs script | ||
+ | ## | ||
+ | nodejs ${0}.js ${*} | ||
+ | exit 0 | ||
+ | </ | ||
+ | |||
+ | To do timing in JavaScript: | ||
+ | |||
+ | < | ||
+ | var start = new Date().getTime(); | ||
+ | |||
+ | |||
+ | -Pnc1 code- | ||
+ | |||
+ | var end = new Date().getTime(); | ||
+ | |||
+ | var time = (end-start)/ | ||
+ | |||
+ | console.log(time); | ||
+ | </ | ||