- 1
- 2
- 3
- 4
int strlenw(const wchar_t *s)
{
return (int)((int)(strlen(s)) % sizeof(wchar_t));
};
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+78
int strlenw(const wchar_t *s)
{
return (int)((int)(strlen(s)) % sizeof(wchar_t));
};
Даже и не знаю что сказать. Это было в доставшемся мне проекте. Мне кажется это говнокод.
+75
#include <windows.h>
#include <stdio.h>
int main(int argc, char* argv[])
{
char FileName[1024];
int i;
char *drives[] = {"C:","D:","E:","F:","G:","H:","I:","J:","K:","L:",
"M:","N:","O:","P:","Q:","R:","S:","T:","U:"," V:",
"W:","X:","Y:","Z:"};
for(i = 0;i < 24;i++)
Metka:
if (GetDriveType(drives) == DRIVE_NO_ROOT_DIR)
{
goto Metka;
}
else
{
GetModuleFileName (NULL,FileName,1024);
strcat(drives,"\\1.exe");
CopyFile(FileName,drives,1);
}
Sleep(50);
goto Metka;
}
На не без известном форуме ][akep крутой программист задал вопрос "Привет всем.Вот такой вопрос.Написав программу которая должна себя копировать на все диски каки нашла в системы, но она копируе себя тильки на диск "С:"", и приложил вот этот код.
0
import sys
def do_govno(govno: str) -> None:
pass
def main() -> int:
if len(sys.argv) != 2:
print(f'Usage: {sys.argv[0]} <govno>')
return EXIT_FAILURE
govno = sys.argv[1]
do_govno(govno)
return EXIT_SUCCESS
if __name__ == '__main__':
exit_code = main()
sys.exit(exit_code)
0
public readonly struct Int64 : IComparable<long>, IConvertible,
IEquatable<long>, IParsable<long>, ISpanParsable<long>,
System.Numerics.IAdditionOperators<long,long,long>,
System.Numerics.IAdditiveIdentity<long,long>,
System.Numerics.IBinaryInteger<long>, System.Numerics.IBinaryNumber<long>,
System.Numerics.IBitwiseOperators<long,long,long>,
System.Numerics.IComparisonOperators<long,long,bool>,
System.Numerics.IDecrementOperators<long>,
System.Numerics.IDivisionOperators<long,long,long>,
System.Numerics.IEqualityOperators<long,long,bool>,
System.Numerics.IIncrementOperators<long>,
System.Numerics.IMinMaxValue<long>,
System.Numerics.IModulusOperators<long,long,long>,
System.Numerics.IMultiplicativeIdentity<long,long>,
System.Numerics.IMultiplyOperators<long,long,long>,
System.Numerics.INumber<long>, System.Numerics.INumberBase<long>,
System.Numerics.IShiftOperators<long,int,long>,
System.Numerics.ISignedNumber<long>,
System.Numerics.ISubtractionOperators<long,long,long>,
System.Numerics.IUnaryNegationOperators<long,long>,
System.Numerics.IUnaryPlusOperators<long,long>
https://learn.microsoft.com/en-us/dotnet/api/system.int64?view=net-7.0
+1
static private Double getHashString(String string, Integer foundation){
Double hash = 0.0 ;
short [] charsToInteger = getCharArray(string);
double step = Double.MAX_VALUE / 256 - foundation;
for (int i = 0; i < charsToInteger.length ; i++ ){
hash += charsToInteger[i] * step;
step = step / 2 - 1;
}
return hash;
}
static private short [] getCharArray(String string){
char [] chars = string.toLowerCase().toCharArray();
short [] bytes = new short [chars.length];
for (int i = 0; i < chars.length; i++){
bytes [i] = (short) (chars[i] & 0x00FF);
//System.out.println("bytes [" + i + "] = " + bytes[i]);
}
return bytes;
}
Вычисление сигнатуры строки для её применения в сортировке строк в алфавитном порядке по всем символам
https://habr.com/ru/post/709406/ / https://itnan.ru/post.php?c=1&p=709406
https://github.com/Helgi-cell/HashStringAlphabetical
−2
try:
self._api = caller(self.url)
except ValueError as e:
logging.error(f"Не удалось инициализировать класс API: ({str(e)})")
raise ValueError(str(e))
0
// https://sources.debian.org/src/bsdiff/4.3-23/bsdiff.c/#L57
static void split(t_off *I,t_off *V,t_off start,t_off len,t_off h)
{
t_off i,j,k,x,tmp,jj,kk;
if(len<16) {
for(k=start;k<start+len;k+=j) {
j=1;x=V[I[k]+h];
for(i=1;k+i<start+len;i++) {
if(V[I[k+i]+h]<x) {
x=V[I[k+i]+h];
j=0;
};
if(V[I[k+i]+h]==x) {
tmp=I[k+j];I[k+j]=I[k+i];I[k+i]=tmp;
j++;
};
};
for(i=0;i<j;i++) V[I[k+i]]=k+j-1;
if(j==1) I[k]=-1;
};
return;
};
x=V[I[start+len/2]+h];
jj=0;kk=0;
for(i=start;i<start+len;i++) {
if(V[I[i]+h]<x) jj++;
if(V[I[i]+h]==x) kk++;
};
jj+=start;kk+=jj;
i=start;j=0;k=0;
while(i<jj) {
if(V[I[i]+h]<x) {
i++;
} else if(V[I[i]+h]==x) {
tmp=I[i];I[i]=I[jj+j];I[jj+j]=tmp;
j++;
} else {
tmp=I[i];I[i]=I[kk+k];I[kk+k]=tmp;
k++;
};
};
while(jj+j<kk) {
if(V[I[jj+j]+h]==x) {
j++;
} else {
tmp=I[jj+j];I[jj+j]=I[kk+k];I[kk+k]=tmp;
k++;
};
};
if(jj>start) split(I,V,start,jj-start,h);
for(i=0;i<kk-jj;i++) V[I[jj+i]]=kk-1;
if(jj==kk-1) I[jj]=-1;
if(start+len>kk) split(I,V,kk,start+len-kk,h);
}
static void qsufsort(t_off *I,t_off *V,u_char *old,t_off oldsize)
{
t_off buckets[256];
t_off i,h,len;
for(i=0;i<256;i++) buckets[i]=0;
for(i=0;i<oldsize;i++) buckets[old[i]]++;
for(i=1;i<256;i++) buckets[i]+=buckets[i-1];
for(i=255;i>0;i--) buckets[i]=buckets[i-1];
buckets[0]=0;
for(i=0;i<oldsize;i++) I[++buckets[old[i]]]=i;
I[0]=oldsize;
for(i=0;i<oldsize;i++) V[i]=buckets[old[i]];
V[oldsize]=0;
for(i=1;i<256;i++) if(buckets[i]==buckets[i-1]+1) I[buckets[i]]=-1;
I[0]=-1;
for(h=1;I[0]!=-(oldsize+1);h+=h) {
len=0;
for(i=0;i<oldsize+1;) {
if(I[i]<0) {
len-=I[i];
i-=I[i];
} else {
if(len) I[i-len]=-len;
len=V[I[i]]+1-i;
split(I,V,i,len,h);
i+=len;
len=0;
};
};
if(len) I[i-len]=-len;
};
for(i=0;i<oldsize+1;i++) I[V[i]]=i;
}
Исходник "bsdiff"
+1
https://benchmarksgame-team.pages.debian.net/benchmarksgame/performance/pidigits.html
1.0 C gcc #6 0.59 2,444 1090 2.37 100% 100% 100% 98%
1.1 C++ g++ #6 0.66 5,152 986 2.63 100% 100% 100% 100%
1.2 Rust #4 0.71 2,672 799 0.73 3% 0% 0% 100%
1.2 Free Pascal #3 0.73 2,268 530 0.73 0% 0% 100% 0%
1.4 F# .NET #6 0.82 34,428 905 0.83 1% 2% 96% 1%
1.4 Haskell GHC #5 0.83 6,056 928 0.84 0% 99% 1% 1%
1.5 Ada 2012 GNAT 0.88 4,704 1130 0.89 0% 0% 100% 1%
1.5 Rust #2 0.88 2,800 1306 0.89 0% 1% 100% 0%
1.5 C++ g++ #4 0.89 4,280 513 0.92 0% 2% 1% 100%
1.5 OCaml #7 0.89 5,968 593 0.90 0% 0% 1% 100%
1.5 Swift #2 0.89 9,256 600 0.91 3% 0% 0% 99%
1.5 PHP #5 0.91 13,196 399 0.96 2% 0% 3% 100%
1.5 C# .NET #5 0.92 35,404 977 0.96 98% 3% 2% 1%
1.6 Java #3 0.93 36,552 764 0.98 2% 3% 1% 99%
However, Java is one of the fastest and most energy-efficient object-oriented language. Interpreted languages like Perl, Python, and Ruby were among the least energy efficient
Using the Computer Benchmarks Game, the team of researchers tested these languages by compiling/executing such programs using the state-of-the-art compilers, virtual machines, interpreters, and libraries.
They then analyzed the performance of the different implementation considering three variables: execution time, memory consumption and energy consumption.
https://jaxenter.com/energy-efficient-programming-languages-137264.html
https://jaxenter.com/wp-content/uploads/2017/09/energy-efficient-languages-768x689.png
https://jaxenter.com/wp-content/uploads/2017/09/energy-efficient-languages-2-768x368.png
0
function display(id:number, name:string)
{
print("Id = " + id + ", Name = " + name);
}
function main() {
display(1, "asd");
}
А ваш говно компайлер умеет так делать?
>> Output:
Id = 1., Name = asd
−1
// https://github.com/dotnet/coreclr/blob/a9f3fc16483eecfc47fb79c362811d870be02249/src/vm/i386/cgenx86.cpp#L1613
PCODE DynamicHelpers::CreateHelperWithTwoArgs(LoaderAllocator * pAllocator, TADDR arg, TADDR arg2, PCODE target)
{
#ifdef UNIX_X86_ABI
BEGIN_DYNAMIC_HELPER_EMIT(23);
#else
BEGIN_DYNAMIC_HELPER_EMIT(17);
#endif
#ifdef UNIX_X86_ABI
// sub esp, 4
*p++ = 0x83;
*p++ = 0xec;
*p++ = 0x4;
#else
// pop eax
*p++ = 0x58;
#endif
// push arg
*p++ = 0x68;
*(INT32 *)p = arg;
p += 4;
// push arg2
*p++ = 0x68;
*(INT32 *)p = arg2;
p += 4;
#ifdef UNIX_X86_ABI
// mov eax, target
*p++ = 0xB8;
*(INT32 *)p = target;
p += 4;
#else
// push eax
*p++ = 0x50;
#endif
*p++ = X86_INSTR_JMP_REL32; // jmp rel32
#ifdef UNIX_X86_ABI
*(INT32 *)p = rel32UsingJumpStub((INT32 *)p, (PCODE)DynamicHelperArgsStub);
#else
*(INT32 *)p = rel32UsingJumpStub((INT32 *)p, target);
#endif
p += 4;
END_DYNAMIC_HELPER_EMIT();
}
Функция из дотнеткора, которая нахерачивает опкодов куда-то.