built-in

Is it normal that the gcc atomic builtins are so slow?

拈花ヽ惹草 提交于 2019-12-04 03:45:55
I have an application where I have to increment some statistics counters in a multi-threaded method. The incrementing has to be thread-safe, so I decided to use the gcc atomic builtins __sync_add_and_fetch() function. Just to get an idea of their impact, I did some simple performance testing and noticed that these functions are much slower than simple pre/post incrementing. Here is the test program that I created: #include <iostream> #include <pthread.h> #include <time.h> using namespace std; uint64_t diffTimes(struct timespec &start, struct timespec &end) { if(start.tv_sec == end.tv_sec) {

Where can I find information about Perl's special variables?

百般思念 提交于 2019-12-04 03:42:01
问题 Perl has quite a few special variables such as @F , $! , %! ... etc. Where are all Perl's special variables documented? 回答1: All special variables used by Perl are documented in perldoc perlvar. You can view this document on your computer by running perldoc perlvar The documentation for a specific special variable can also be accessed at the command line using perldoc -v : perldoc -v @F You may need to escape/quote some variables to avoid interpolation by your shell: perldoc -v '$!' or

Built-in magic variable names/attributes

末鹿安然 提交于 2019-12-04 03:19:00
Background : For those not familiar with it, Sublime Text (and TextMate) provides syntax highlighting and other features through scopes which are defined by .tmLanguage language definition files, basically a bunch of regexes to identify various constructs in a given language, such as function definitions, various types of strings, reserved words, etc. I'm the maintainer of the Python Improved package (available via Package Control if you're interested) that aims to be a better language definition for Python. You can read about it at GitHub if you want, but one of the key features is that it's

List all built-in functions in javascript?

萝らか妹 提交于 2019-12-04 01:07:32
问题 Is there a way in js to list all the builtin functions and some info on their parameterlists? I couldn't really find anything about reflection to do this sort of thing edit: The functions such as Math.sin are actually the ones I want to list, actually all built-in functions. 回答1: Something like this, maybe? for( var x in window) { if( window[x] instanceof Function) console.log(x); } This will list all native functions in the console (excluding one in native objects, such as Math.sin() ). 来源:

Which version of R is running in my computer?

时光毁灭记忆、已成空白 提交于 2019-12-04 00:32:43
There are two R directories on my computer: one is /home/R-2.15.2 ,the other is /home/R-2.15.1 , when I input R , I can start R, now I want to know which R is running: 2.15.1 or 2.15.2? Run R --version there's info about version on the first line. Edit: If you ask this question then I bet that R is not running from any of these directories. Check $PATH env variable to get information where binaries are looked for and in which order. Edit 2: Use type shell command to find where binary for given command is stored, -a for all paths, -f for the hashed one (basically: most recently used). In

Is it OK to raise a built-in exception, but with a different message, in Python?

纵饮孤独 提交于 2019-12-03 23:46:16
Is it OK to raise a built-in exception with a custom text? or to raise a built-in warning also with custom text? The documentation reads: exception ValueError: Raised when a built-in operation or function receives an argument (…) Is it implied that only built-in operations should raise a ValueError exception? In practice, I understand that it is safe to create an exception class that inherits from ValueError or Exception. But is it OK not to do that, and directly raise a ValueError("custom text")? Since ValueError is built-in, raising a ValueError (with a custom text) allows users to quickly

In bash, how to get the current status of set -x?

允我心安 提交于 2019-12-03 23:00:55
I would like to set -x temporarily in my script and then return in to the original state. Is there a way to do it without starting new subshell? Something like echo_was_on=....... ... ... if $echo_was_on; then set -x; else set +x; fi You can check the value of $- to see the current options; if it contains an x, it was set. You can check like so: old_setting=${-//[^x]/} ... if [[ -n "$old_setting" ]]; then set -x; else set +x; fi shellter Or in a case statement case $- in *x* ) echo "X is set, do something here" ;; * ) echo "x NOT set" ;; esac Here are re-usable functions, based on @shellter's

__builtin_trap: when to use it?

…衆ロ難τιáo~ 提交于 2019-12-03 22:56:00
gcc provides additional builtin functions "for optimization". One of them is void __builtin_trap (void) which essentially is here to abort the program by executing an illegal command. From the doc: __builtin_trap function causes the program to exit abnormally. GCC implements this function by using a target-dependent mechanism (such as intentionally executing an illegal instruction) or by calling abort. The mechanism used may vary from release to release so you should not rely on any particular implementation. Why would you ever use this rather than exit(1) or abort ? Why did the gcc developers

Python inverse function of id(…) built-in function

倾然丶 夕夏残阳落幕 提交于 2019-12-03 14:48:00
Is there a reverse or inverse of the id built-in function? I was thinking of using it to encode and decode string without taking too much time or having a lot of overhead like the PyCrypto library. The need for me is quite simple so I don't want to use PyCrypto for a simple encode and decode. Something like: >>> id("foobar") 4330174256 >>> reverse_id(4330174256) # some function like this to reverse. "foobar" Victor Castillo Torres I do not wanna to steal the credits from the man who answered the question This can be done easily by ctypes: import ctypes a = "hello world" print ctypes.cast(id(a)

Why can't I use builtin for classes that overload subsref?

ⅰ亾dé卋堺 提交于 2019-12-03 14:31:46
问题 I would like to overload only one type of subsref calls (the '()' type) for a particular class and leave any other calls to Matlab's built in subsref -- specifically, I want Matlab to handle property/method access via the '.' type. But, it seems like Matlab's 'builtin' function doesn't work when subsref is overloaded in a class. Consider this class: classdef TestBuiltIn properties testprop = 'This is the built in method'; end methods function v = subsref(this, s) disp('This is the overloaded