- 1
"Performance is easy. All you need to know is everything" (c) S. Kuksenko (@kuksenk0)
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+1
"Performance is easy. All you need to know is everything" (c) S. Kuksenko (@kuksenk0)
Умеете профилировать программы?
Знаете, что такое flame diagram? Умеете посмотреть стектрейс от входа в тред до какого-нить спинлока в ядре? Смотрите асм своего компилятора или джита? Знаете, какая инструкция сколько занимает?
Умеете по vmstat/iostat или xperf/perf counters увидать проблему и соотнести ее с программой? Используете dtrace голый или с instruments? yourkit? vTune? valgrind? bpf?
Или такие же дебилы, как я?
+1
public int HowManyHoursWillGoBackForConvertingUkToUtc(DateTime ukTime) => IsAlreadyGoForward(ukTime) ? 1 : 0;
когда название говорит само за себя
+1
<?php
require_once '../vendor/autoload.php';
require_once 'functions.php';
require_once 'KPFile.php';
require_once 'KPLogger.php';
use Intervention\Image\ImageManagerStatic as Шакализатор;
Шакализатор::configure(array('driver' => 'imagick'));
$logger = new KPLogger();
function сжать(KPFile $шакал, $степеньСжатия, Array $ебучесть, $output) {
$индексЕбучести = 0;
if (!is_null($ебучесть[0])) {
$индексЕбучести = $ебучесть[0];
}
if (!is_null($ебучесть[1]) && ($ебучесть[1] > $ебучесть[0])) {
$индексЕбучести = $ебучесть[1];
}
$img = Шакализатор::make($шакал->path);
$img->resize($ебучесть[0], $ебучесть[1], function ($constraint) {
$constraint->aspectRatio();
$constraint->upsize();
});
if ($img->mime() !== 'image/jpeg') {
$img->encode('jpg', 100);
}
$img->save($output."$шакал->name-$индексЕбучести.jpg", $степеньСжатия);
}
function сжатьВсехШакалов($path, $степеньСжатия, $ебучестьШакалов, $output) {
global $logger;
$files = scandir($path);
foreach($files as $key => $file) {
$logger->colorLogWithFiles('blue', $file, $key);
try {
$шакал = new KPFile($path.$file);
if ($шакал->type !== KPFile::FILE_TYPE_IMAGE) {
continue;
}
if (trim($шакал->name) == '') {
throw new Exception("file=$file, kpFileName=$шакал->name");
}
foreach ($ебучестьШакалов as $ебучесть) {
сжать($шакал, $степеньСжатия, $ебучесть, $output);
}
} catch (Exception $e) {
$logger->exception($e, $key);
}
}
}
$степеньСжатия = 22;
$ебучестьШакалов = [
[60, 60],
[38, 38]
];
сжатьВсехШакалов('dataHeavy/carsOrig/', $степеньСжатия, $ебучестьШакалов, "../public/img/cars/");
$logger->colorLogWithFiles('blue', '10/10 *** еб/шакалов', null, "\n");
shakal of jpeg-street
+1
#include "pch.h"
#include <iostream>
#include <conio.h>
#include <stdlib.h>
#include <ctime>
using namespace std;
int main()
{
setlocale(0, "rus");
int n, a[1000], max, c;
cout << "число элементов: "; cin >> n;
srand(time(0));
cout << "\nчисла массива:\n";
for (int i = 0; i < n; i++) {
a[i] = rand() % 2000 -1000;
cout << a[i] << " ";
if (i == 0) max = abs(a[i]); else if (abs(a[i]) > max) max = abs(a[i]);
}
cout << "\n\nабс. максимум = " << max << endl;
for (int i = 0; i < n; i++) {
for (int j = n-1; j > 0; j--) {
if (a[j - 1] < a[j]) {
c = a[j - 1];
a[j - 1] = a[j];
a[j] = c;
}
}
}
cout << "\nотсортированный массив:\n";
for (int i = 0; i < n; i++) {
cout << a[i]<<" ";
}
_getch();
return 0;
}
+1
// File icontact.h
// Describes a contact in the address book
class IContact
{
public:
virtual ~IContact();
virtual void ...
...
void setContact(const QString& contact);
...
private:
QString m_contact;
// ... other fields ...
};
// File icontact.cpp
void IContact::setContact(const QString &contact)
{
m_contact = contact;
}
"Ну и че тут непонятного?" (Senior software developer, 8+ years of experience)
+1
// https://jaycarlson.net/2019/09/06/whats-up-with-these-3-cent-microcontrollers/
// The C code I used for those original MCU tests looked something like this:
volatile int16_t in[25];
volatile int16_t out[25];
const int16_t a0 = 16384;
const int16_t a1 = -32768;
const int16_t a2 = 16384;
const int16_t b1 = -25576;
const int16_t b2 = 10508;
int16_t z1, z2;
int16_t outTemp;
int16_t inTemp;
void main()
{
while(1) {
_pa = 2;
for(i=0;i<25;i++)
{
inTemp = in[i];
outTemp = inTemp * a0 + z1;
z1 = inTemp * a1 + z2 - b1 * outTemp;
z2 = inTemp * a2 - b2 * outTemp;
out[i] = outTemp;
}
_pa = 0;
}
}
// The Padauk code looks like this:
WORD in[11];
WORD out[11];
WORD z1, z2;
WORD pOut, pIn; // these are pointers, but aren't typed as such
int i;
void FPPA0 (void)
{
.ADJUST_IC SYSCLK=IHRC/2 // SYSCLK=IHRC/2
PAC.6 = 1; // make PA6 an output
while(1) {
PA.6 = 1;
pOut = out;
pIn = in;
i = 0;
do {
*pOut = (*pIn << 14) + z1;
z1 = -(*pIn << 15) + z2
+ (*pOut << 14)
+ (*pOut << 13)
+ (*pOut << 9)
+ (*pOut << 8)
+ (*pOut << 7)
+ (*pOut << 6)
+ (*pOut << 5)
+ (*pOut << 3);
z2 = (*pIn << 14)
- (*pOut << 13)
- (*pOut << 11)
- (*pOut << 8)
- (*pOut << 3)
- (*pOut << 2);
i++;
pOut++;
pIn++;
} while(i < 11);
PA.6 = 0;
}
}
> As for the filter function itself, you’ll see that all the multiplies have been replaced with shift-adds. The Padauk part does not recognize the * operator for multiplication; trying to use it to multiply two variables together results in a syntax error. No, I’m not joking.
+1
<?php
function split_hash($hash, $sizes) {
$cnt = count($sizes); // количество словарей
$partSize = floor(128/4/$cnt); // размер части хэша в тетрадах
$result = array();
foreach($sizes as $size) {
$tmp = substr($hash, 0, $partSize); // разбиваем хэш по тетрадам на равные части
$hash = substr($hash, $partSize);
$result[] = gmp_intval(gmp_mod(gmp_init($tmp, 16), $size)); // возвращаем остаток от деления фрагмента хэша
// на размер словаря
}
return $result;
}
function R($hash, $dicts) {
$sizes = array_map(function($val){return count($val);}, $dicts); // получаем размеры каждого словаря
$indices = split_hash($hash, $sizes);
$result = '';
foreach($indices as $dictNumber=>$index) {
$result .= $dicts[$dictNumber][$index]; // сцепляем слово из частей
}
return $result;
}
function make_chain($start, $length, $dicts) {
for($i = 0; $i < $length; ++$i) {
$hash = md5($start);
echo $hash . ' : ' . $start . PHP_EOL;
$start = R($hash, $dicts);
}
}
make_chain('свинособака', 10, array(
array('свино', 'овце', 'тигро', 'косатко', 'зубро', 'волко', 'кото'),
array('собака', 'бык', 'лев', 'дельфин', 'бизон')
));
Выводит:
360629d3cf05cee0240a23e1251c58a0 : свинособака
1f7ad860b089c0e1141de02ac1e6e3ef : волкобизон
6f2e4e3025c9dd840f1fa4a78792ef31 : котобизон
d5812761186013ecca674a2704d5a081 : зубробык
b4499d259156939bb74cbc1743632c8d : овцебизон
c28ad194fcc581f538d109f8acb6b1f5 : волкобык
663a3e06c88185db8fd4f81829e66b85 : котодельфин
30bb70e972bf073c7aa4ec93c8d5b9a0 : косаткодельфин
cc31cd8554c1add0128013bba2e47317 : волколев
d88e78b7340637370628848b1957b4c2 : котособака
+1
Хочу, чтобы 3.14159265, 1024--, vistefan, kegdan, bormand вернулись в новогоднюю ночь.
+1
Число 1 = 1;
Число номер 2 = 2;
Сумма = Число 1 + Число номер 2;
print Сумма; print;
function Открытие двери в поезде() {
print "Дверь открыта"; print;
}
Открытие двери в поезде();
https://habr.com/ru/sandbox/133385/
+1
size_t nChLen = it_ch_end - it_ch;
до меня дошло не сразу.