performance improvement

master
Avril 4 years ago
parent 96795c0f91
commit ecd5f3181c
Signed by: flanchan
GPG Key ID: 284488987C31F630

1
.gitignore vendored

@ -2,3 +2,4 @@
test* test*
obj/ obj/
hexview hexview
profile/

@ -11,20 +11,37 @@ LDFLAGS+= -lfmt
PROJ = hexview PROJ = hexview
OBJ = $(addprefix obj/,$(SRC:.cpp=.o)) OBJ = $(addprefix obj/,$(SRC:.cpp=.o))
PROF_OBJ = $(addprefix profile/,$(SRC:.cpp=.o))
.PHONY: all .PHONY: all
all: dirs $(PROJ) all: dirs $(PROJ)
dirs: dirs:
@mkdir -p obj/src @mkdir -p obj/src
@mkdir -p profile/src
obj/%.o: %.cpp obj/%.o: %.cpp
$(CXX) -c $< $(_HX_FEAT) $(CXXFLAGS) -o $@ $(LDFLAGS) $(CXX) -c $< $(_HX_FEAT) $(CXXFLAGS) -o $@ $(LDFLAGS)
profile/%.o: %.cpp
$(CXX) -c $< $(_HX_FEAT) $(CXXFLAGS) -fprofile-generate -o $@ $(LDFLAGS)
$(PROJ): $(OBJ) $(PROJ): $(OBJ)
$(CXX) $^ $(CXXFLAGS) -o $@ $(LDFLAGS) $(CXX) $^ $(CXXFLAGS) -o $@ $(LDFLAGS)
strip $@ strip $@
pgo-generate: $(PROF_OBJ)
$(CXX) $^ $(CXXFLAGS) -fprofile-generate -o $@ $(LDFLAGS)
pgo-profile: pgo-generate
for i in {1..32}; do \
dd if=/dev/urandom of=./pgo-test bs=1024 count=1024 \
./pgo-generate ./pgo-test
done
rm ./pgo-test
clean: clean:
rm -f $(PROJ) rm -f $(PROJ)
rm -rf obj rm -rf obj
rm -rf profile
rm -f pgo-generate

@ -53,12 +53,18 @@ inline __attribute__((always_inline)) void prints(const S&... strings)
(fputs((const char*)strings, stdout), ...); (fputs((const char*)strings, stdout), ...);
} }
inline void hex02(std::uint8_t byte, char buffer[3]) inline void hex02(std::uint8_t byte, char buffer[2])
{ {
buffer[0] =hex_map[byte][0]; buffer[0] =hex_map[byte][0];
buffer[1] =hex_map[byte][1]; buffer[1] =hex_map[byte][1];
} }
template<int N>
inline __attribute__((always_inline)) void print_exact(const char (&ar)[N])
{
fwrite(ar, N, 1, stdout);
}
namespace hv { namespace hv {
void print_screen(const span<unsigned char> memory, unsigned long offset) void print_screen(const span<unsigned char> memory, unsigned long offset)
{ {
@ -71,28 +77,34 @@ namespace hv {
fmt::print("0x{:016x} ", offset); fmt::print("0x{:016x} ", offset);
char hxbuf[3]; char hxbuf[3];
std::size_t i=0; std::size_t i=0;
char ascii[1 + ROW_SZ]; char r_ascii[2 + ROW_SZ];
r_ascii[0] = ' ';
ascii[ROW_SZ] = 0; r_ascii[1] = ' ';
hxbuf[2] = 0; char* ascii = r_ascii + 2;
hxbuf[2] = ' ';
for(;i<memory.size();i++) { for(;i<memory.size();i++) {
if (i && i % ROW_SZ == 0) { if (i && i % ROW_SZ == 0) {
prints(" ", S ascii); print_exact(r_ascii);
fmt::print("\n0x{:016x} ", i+offset); fmt::print("\n0x{:016x} ", i+offset);
} }
unsigned char idx = memory[i]; unsigned char idx = memory[i];
hex02(idx, hxbuf); hex02(idx, hxbuf);
prints(hxbuf, " "); print_exact(hxbuf);
ascii[i%ROW_SZ] = ascii_map[idx]; ascii[i%ROW_SZ] = ascii_map[idx];
} }
if (memory.size() % ROW_SZ != 0) if (memory.size() % ROW_SZ != 0)
{ {
auto rest = memory.size() % ROW_SZ; auto rest = memory.size() % ROW_SZ;
ascii[rest] = 0; ascii[rest] = 0;
constexpr const char output[3] = { ' ', ' ', ' ' };
for(std::size_t j=0;j< ROW_SZ - rest;j++) for(std::size_t j=0;j< ROW_SZ - rest;j++)
prints(" "); print_exact(output);
prints(r_ascii);
}
else {
print_exact(r_ascii);
} }
fmt::print(" {}", S ascii);
} }
} }

Loading…
Cancel
Save