Skip to content

Commit 385a1f1

Browse files
committed
Add the elapsed time section
1 parent 3b65d9f commit 385a1f1

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

VimScriptForPythonDevelopers.MD

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# Vim Script for Python Developers
22

3-
A guide to Vim Script development for Python developers. Sample code for the various expressions, statements, functions and programming constructs is shown in both Python and Vim Script. This is not intended to be a tutorial for developing Vim scripts. It is assumed that the reader is familiar with programming in Python.
3+
A guide to Vim Script development for Python developers. Sample code for the various expressions, statements, functions and programming constructs is shown in both Python and Vim Script. This is not intended to be a tutorial for developing Vim scripts. It is assumed that the reader is familiar with Python programming.
44

55
For an introduction to Vim Script development, refer to [usr_41.txt](https://vimhelp.org/usr_41.txt.html), [eval.txt](https://vimhelp.org/eval.txt.html) and [Learn Vimscript the Hard Way](https://learnvimscriptthehardway.stevelosh.com/)
66

7-
For a similar guide for JavaScript developers, refer to [Vim Script for the JavaScripter](https://w0rp.com/blog/post/vim-script-for-the-javascripter/)
7+
For a guide similar to this one for JavaScript developers, refer to [Vim Script for the JavaScripter](https://w0rp.com/blog/post/vim-script-for-the-javascripter/)
88

99
This guide only describes the programming constructs that are present in both Python and Vim. The constructs that are unique to Vim (e.g. [autocommands](https://vimhelp.org/autocmd.txt.html#autocommands), [key-mapping](https://vimhelp.org/map.txt.html#key-mapping), [abbreviations](https://vimhelp.org/map.txt.html#abbreviations), [user-commands](https://vimhelp.org/map.txt.html#user-commands), [plugins](https://vimhelp.org/usr_05.txt.html#plugin), etc.) are not described in this guide.
1010

11-
Some of the features described in this guide are available are only in recent versions of Vim (8.1).
11+
Some of the features described in this guide are available only in the recent versions of Vim (8.2).
1212

1313
The Github repository for this gist is available at: https://github.com/yegappan/VimScriptForPythonDevelopers.
1414

@@ -2587,6 +2587,32 @@ echo localtime()
25872587

25882588
*Help:* [localtime()](https://vimhelp.org/eval.txt.html#localtime%28%29)
25892589

2590+
### Measuring elapsed time
2591+
2592+
**Python:**
2593+
```python
2594+
import time
2595+
start_time = time.perf_counter()
2596+
sum = 1
2597+
for i in range(1000):
2598+
sum += i
2599+
end_time = time.perf_counter()
2600+
print("Elapsed time " + str(end_time - start_time))
2601+
```
2602+
2603+
**VimScript:**
2604+
```vim
2605+
let start = reltime()
2606+
let sum = 0
2607+
for i in range(1000)
2608+
let sum += i
2609+
endfor
2610+
let elapsed_time = reltime(start)
2611+
echo "Elasped time" reltimefloat(elapsed_time)
2612+
```
2613+
2614+
*Help:* [reltime()](https://vimhelp.org/eval.txt.html#reltime%28%29), [reltimestr()](https://vimhelp.org/eval.txt.html#reltimestr%28%29), [reltimefloat()](https://vimhelp.org/eval.txt.html#reltimefloat%28%29)
2615+
25902616
------------------------------------------------------------------------------
25912617

25922618
## External commands

0 commit comments

Comments
 (0)