This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MIT License | |
Copyright (c) 2021 Daniel Ethridge | |
Permission is hereby granted, free of charge, to any person obtaining a copy | |
of this software and associated documentation files (the "Software"), to deal | |
in the Software without restriction, including without limitation the rights |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# threadSafeFuture.nim | |
# Jens Alfke, 30 June 2020 | |
import asyncdispatch, deques, locks, sugar, threadpool | |
## Utilities for mixing async/await with threads. | |
## | |
## ``threadSafe()`` takes a Future and returns a new Future that can be completed on any thread. | |
## The original Future's callback will still be invoked on its original thread, and ``await`` | |
## works normally. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# nim c -r --threads:on --gc:orc | |
import cpuinfo, os, random, locks, deques | |
type | |
WorkReq = ref object | |
id: int | |
WorkRes = ref object | |
id: int |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import stackless | |
class T: | |
metric = 0 | |
instance_T = T | |
def increment_T_metric(instance): | |
instance.metric += 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This came from https://github.com/xmonader/nim-linkcheck | |
# I just added the parallel example to the code and slightly modified the output formatting. | |
# My tests yielded the following numbers | |
# Sequential : 6.77 seconds | |
# Async : 0.27 seconds (25.07x faster | 3.988% time of sequential | 96.01 % faster) | |
# Parallel : 0.34 seconds (19.91x faster | 5.022% time of sequential | 94.98 % faster) | |
import os, httpclient | |
import strutils | |
import times |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import locks, threadpool, strutils | |
# compile with: | |
# nim c -r --threads:on -d:danger --gc:arc | |
{.experimental: "parallel".} | |
var | |
lock: Lock | |
a: seq[string] | |
initLock lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import locks, threadpool, strutils | |
# compile with: | |
# nim c -r --threads:on -d:danger --gc:arc | |
{.experimental: "parallel".} | |
var | |
lock: Lock | |
a: array[20, string] | |
initLock lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import locks, threadpool, strutils | |
# compile with: | |
# nim c -r --threads:on -d:danger --threadanalysis:off --gc:arc | |
{.experimental: "parallel".} | |
var | |
lock: Lock | |
a: array[20, string] | |
initLock lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import locks, threadpool, strutils | |
{.experimental: "parallel".} | |
var | |
lock: Lock | |
a {.guard: lock.}: array[20, string] | |
initLock lock | |
proc process(s: string): string = |
NewerOlder