Skip to content

Instantly share code, notes, and snippets.

using System;
using System.Threading;
using System.Threading.Tasks;
namespace ConsoleApp1
{
class Program
{
static SemaphoreSlim mSema1 = new SemaphoreSlim(1);
static SemaphoreSlim mSema2 = new SemaphoreSlim(0);
@patricksuo
patricksuo / latency.txt
Created October 9, 2017 02:25 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers
--------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@patricksuo
patricksuo / dotnet-mapgen-v2.py
Created October 6, 2017 17:02 — forked from goldshtn/dotnet-mapgen-v2.py
dotnet-mapgen: generates map files for crossgen-compiled assemblies, and merges them into the main perf map file
#!/usr/bin/env python
#
# USAGE: dotnet-mapgen [-h] {generate,merge} PID
#
# In generate mode, this tool reads the /tmp/perfinfo-PID.map file generated
# by the CLR when running with COMPlus_PerfMapEnabled=1, and finds all load
# events for managed assemblies. For each managed assembly found in this way,
# the tool runs crossgen to generate a symbol mapping file (akin to debuginfo).
#
# In merge mode, this tool finds the load address of each managed assembly in
@patricksuo
patricksuo / coreclr-usdt.patch
Created October 5, 2017 23:38 — forked from goldshtn/coreclr-usdt.patch
.NET Core (CoreCLR) patch for emitting USDT probes
diff --git a/src/scripts/genXplatLttng.py b/src/scripts/genXplatLttng.py
index bacf034..3d40d77 100644
--- a/src/scripts/genXplatLttng.py
+++ b/src/scripts/genXplatLttng.py
@@ -407,8 +407,25 @@ def generateLttngTpProvider(providerName, eventNodes, allTemplates):
for eventNode in eventNodes:
eventName = eventNode.getAttribute('symbol')
templateName = eventNode.getAttribute('template')
+
+ template = allTemplates[templateName] if templateName else None
#!/usr/bin/env bash
# alias godev="source /usr/local/bin/godev"
EchoHelp() {
echo "Hello"
}
NewGoProject() {
@patricksuo
patricksuo / Profile.ps1
Created August 16, 2017 02:31
powershell dot file
# https://blogs.technet.microsoft.com/heyscriptingguy/2012/05/21/understanding-the-six-powershell-profiles/
#Description
#Path
#Current User, Current Host - console
#$Home\[My ]Documents\WindowsPowerShell\Profile.ps1
#Current User, All Hosts
#$Home\[My ]Documents\Profile.ps1
#All Users, Current Host - console
#$PsHome\Microsoft.PowerShell_profile.ps1
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework>
<DefineConstants Condition="'$(OS)' == 'Windows_NT'">AAA;IS_WIN </DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(MSBuildRuntimeType)' == 'Core'">
<DefineConstants Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::OSX)))' == 'true'">AAA;IS_OSX</DefineConstants>
<DefineConstants Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Linux)))' == 'true'">AAA;IS_LINUX</DefineConstants>
using System;
namespace threadpool_bench
{
class Program
{
static int totalRound;
static System.Threading.ManualResetEventSlim finishEvent;
static System.Threading.WaitCallback job = obj =>
PWD=`pwd`
for file in `find $PWD`; do
echo $file
sed -i 's/XXX/YYY/g' $file
done
package power2
// 如果一个数是2的整数次方,那么 取模 可以有优化成一条 AND 指令
// http://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2
// 思想是把最高有效位塞给其余的地位,第一次塞1位,第二次塞2位,第三次塞4位 第四次塞8位 第五次塞16位
// 最多需要做 lg(N) 次 SHIFT + lg(N) 次 OR 既可, N是参数的位数
// run on go playground https://play.golang.org/p/-3O7xKuQ-D
func RoundUpPowerOf2(a uint32) uint32 {
if a <= 1 {
return 2