Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DO NOT MERGE] Pr get ticks #8

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions testcases/t10333.nim
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,45 @@ when defined case1:
# test(cpuTime)
test(getMonoTime)
test(getTicks)

when defined case2:
# include system/timers
# import t10333b
import std/timers
import std/monotimes
import times
import strutils
proc toSeconds(a: Nanos): float = a.float*1e-9
proc toSeconds(a: float): float = a
proc toSeconds(a: Duration): float = a.nanoseconds.float*1e-9


template test(fun)=
block:
proc main()=
# let n = 10_000_000
let n = 100_000_000
type T = type(fun()-fun())
var dt: T
for i in 0..<n:
let t = fun()
# code to benchmark here (intentionally empty)
# let t2 = fun()
# dt += t2-t
echo "\n" & astToStr(fun) & ":"
echo ("total secs", dt.toSeconds)
echo ("ns/iter", (dt.toSeconds * 1e9 / n.float).formatEng)
echo ("iters per sec", (n.float / dt.toSeconds).formatEng)
let tot = cpuTime()
main()
echo ("tot: ", cpuTime() - tot)

# test(cpuTime)
test(getMonoTime)
test(getTicks)

test(getMonoTime)
test(getTicks)

test(getMonoTime)
test(getTicks)
1 change: 1 addition & 0 deletions testcases/tests/t10467/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.js
13 changes: 13 additions & 0 deletions testcases/tests/t10467/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- D20200331T180615 -->
<!DOCTYPE html>
<html>
<head>
<title>test D20200331T180615</title>
<script src = "test1.js" type = "text/javascript"/></script>
</head>
<body>
<h1>Hello world!</h1>
<input type = "button" onclick = "fun1();" name = "ok1" value = "Click Me1" />
<input type = "button" onclick = "fun2();" name = "ok2" value = "Click Me2" />
</body>
</html>
10 changes: 10 additions & 0 deletions testcases/tests/t10467/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
nim js --lib:$nim_prs_D/lib test1.nim
open index.html
click on `click me 2`

test1.js:781 Uncaught TypeError: x_2993010.$ is not a function
at add_quoted_2993006 (test1.js:781)
at HEX24_2991814 (test1.js:822)
at handle_selection2_2990029 (test1.js:890)
at fun2 (test1.js:904)
at HTMLInputElement.onclick (index.html:11)
20 changes: 20 additions & 0 deletions testcases/tests/t10467/test1.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# D20200331T180615
import dom

# import dom except `$`
# when defined case_bug:
# proc `$`*(s: Selection): string = $(s.toString())

proc handleSelection1(a: cstring) =
echo ("fun1", a)

proc handleSelection2(a: Selection) =
echo ("fun2", a)
let b = $a # BUG here
echo ("fun2b", b)

proc fun1*() {.exportc.} =
handleSelection1(document.getSelection())

proc fun2*() {.exportc.} =
handleSelection2(document.getSelection())