mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-06 21:17:48 +00:00
* ttables: smaller table, 5x speedup * thavlak: less iterations, less loops; 30% speedup * tasyncclosestall: shorter timeout; 35% speedup * gcleak4: less iterations, 2x speedup * ttimes: remove deprecated stuff * tdangerisrelease: remove cpp backend, 3x speedup * tfrexp1: smaller range, 2x speedup * trtree: fix warnings, less iterations, 6x speedup * tasyncawait_cyclebreaker: smaller swarm size; 2x speedup * trealloc: smaller number of iterations; 10x speedup * towned_binary_tree: less iterations, 4x speedup * tclosure: remove unused code, less iterations; 2x speedup * twaitany: less durations; 1.4x speedup * tasync_misc: less iterations, 2x speedup * t8535: smaller sleep, 1.5x speedup * tmanyjoin: smaller sleep, 2x speedup * t12221: shorter sleeps, removed two slower tests; 1.6x speedup * tfuturestream: smaller sleep; 1.5x speedup * growobjcrash: less iterations; 2x speedup * ttryrecv: smaller sleep; 1.5x speedup * treusetvar: less threads; 2x speedup * delete tthreadanalysis2, basically a duplicate of tthreadanalysis * t7758: less iterations, 1.5x speedup * tasyncawait: smaller swarm, less messages; 1.5x speedup * tjsandnativeasync: smaller sleep, 1.5x speedup * tpendingcheck: smaller sleep, 1.5x speedup * remove rodfiles test category * move tseq from its own category to 'collections' category * remove unneeded tests and helpers from 'assert' category * stdlib: merge tbitops2 into tbitops * remove 'trepr2' from 'stdlib' cat * merge 'tstreams' into one file * remove 'tinefficient_const_table' from 'ccbugs' cat * merge 'tcollections_to_string' into 'tcollections' * tblocking_channel: smaller sleep, small speedup * tconvexhull: less iterartions; 1.2x speedup * merge 'tdeepcopy2' into 'tdeepcopy' * merge 'tdisjoint_slice2' into 'tdisjoint_slice1' * tmissing_deepcopy: smaller sequence * tsendtwice: smaller arrays; 5x speedup * remove 'tindexerrorformatbounds' * disable multimethod tests * remove 'gc:none' and 'refc' without 'd:useRealtimeGC' from gc tests * koch.nim: bootstrap just with '-d:release', no need for 'csource' * add github workflow for documentation * testament: no need for 8 sub-second decimals
62 lines
1.5 KiB
Nim
62 lines
1.5 KiB
Nim
discard """
|
|
output: '''
|
|
'''
|
|
|
|
ccodeCheck: "\\i ! @'deepCopy(' .*"
|
|
"""
|
|
|
|
# parallel convex hull for Nim bigbreak
|
|
# nim c --threads:on -d:release pconvex_hull.nim
|
|
import algorithm, sequtils, threadpool
|
|
|
|
type Point = tuple[x, y: float]
|
|
|
|
proc cmpPoint(a, b: Point): int =
|
|
result = cmp(a.x, b.x)
|
|
if result == 0:
|
|
result = cmp(a.y, b.y)
|
|
|
|
template cross[T](o, a, b: T): untyped =
|
|
(a.x - o.x) * (b.y - o.y) - (a.y - o.y) * (b.x - o.x)
|
|
|
|
template pro(): untyped =
|
|
while lr1 > 0 and cross(result[lr1 - 1], result[lr1], p[i]) <= 0:
|
|
discard result.pop
|
|
lr1 -= 1
|
|
result.add(p[i])
|
|
lr1 += 1
|
|
|
|
proc half[T](p: seq[T]; upper: bool): seq[T] =
|
|
var i, lr1: int
|
|
result = @[]
|
|
lr1 = -1
|
|
if upper:
|
|
i = 0
|
|
while i <= high(p):
|
|
pro()
|
|
i += 1
|
|
else:
|
|
i = high(p)
|
|
while i >= low(p):
|
|
pro()
|
|
i -= 1
|
|
discard result.pop
|
|
|
|
proc convex_hull[T](points: var seq[T], cmp: proc(x, y: T): int {.closure.}) : seq[T] =
|
|
if len(points) < 2: return points
|
|
points.sort(cmp)
|
|
var ul: array[2, FlowVar[seq[T]]]
|
|
parallel:
|
|
for k in 0..ul.high:
|
|
ul[k] = spawn half[T](points, k == 0)
|
|
result = concat(^ul[0], ^ul[1])
|
|
|
|
var s = map(toSeq(0..9999), proc(x: int): Point = (float(x div 100), float(x mod 100)))
|
|
# On some runs, this pool size reduction will set the "shutdown" attribute on the
|
|
# worker thread that executes our spawned task, before we can read the flowvars.
|
|
setMaxPoolSize 2
|
|
|
|
for i in 0..2:
|
|
doAssert convex_hull[Point](s, cmpPoint) ==
|
|
@[(0.0, 0.0), (99.0, 0.0), (99.0, 99.0), (0.0, 99.0)]
|