Esempio n. 1
0
int main() {
	std::ifstream infile("text3");
	std::vector<std::string> words(10000);
	std::string line;
	while (std::getline(infile, line)) {
		if(line.empty() && line == "") {
			continue;
		}
		words.push_back(line);
	}

	std::vector<std::string> shuffle(words.begin(), words.end());
	std::random_shuffle(shuffle.begin(), shuffle.end());	

	std::vector<size_t> wf(words.size());
	std::vector<size_t> ws(words.size());

	Bench normal;
	const size_t wordsSize = words.size();
	for(size_t i = 0; i < wordsSize; ++i) {
		for(size_t j = 0; j < wordsSize; ++j) {
			if(words[i] == shuffle[j]) {
				wf[i] = j;
				break;
			}
		}
	}
	normal.stop();
	LOG("normal %f", normal.milli());
	LOG("%u %u", words.size(), shuffle.size());

	Bench sse;
	for(size_t i = 0; i < wordsSize; ++i) {
		for(size_t j = 0; j < wordsSize; ++j) {
			if(sse_strcmp(words[i].c_str(), shuffle[j].c_str())) {
				ws[i] = j;
				break;
			}
		}
	}
	sse.stop();
	LOG("normal %f", sse.milli());

	for(size_t i = 0; i < wordsSize; ++i) {
		if(wf[i] != ws[i]) {
			return 1;
		}
	}
	return 0;
}
Esempio n. 2
0
static sse_int
SseUtilNetInfo_GetIPAddressCstr(const sse_char *in_ifname,
				sse_char *out_ipaddr,
				sse_size in_length,
				sse_int in_family)
{
  struct ifaddrs *ifaddr;
  struct ifaddrs *i;
  sse_int family;
  sse_int s;
  
  if (in_ifname == NULL) {
    LOG_ERROR("in_ifname is NULL.");
    return SSE_E_INVAL;
  }
  if (out_ipaddr == NULL) {
    LOG_ERROR("out_ipaddr is NULL.");
    return SSE_E_INVAL;
  }
  if (in_length < NI_MAXHOST) {
    LOG_ERROR("in_length must be NI_MAXHOST(%d) and over.", NI_MAXHOST);
    return SSE_E_INVAL;
  }

  if (getifaddrs(&ifaddr) == -1) {
    LOG_ERROR("getifaddrs() ... failed with [%s]", strerror(errno));
    return SSE_E_GENERIC;
  }

  for (i = ifaddr; i != NULL; i = i->ifa_next) {
    family = i->ifa_addr->sa_family;
    if ((sse_strcmp(i->ifa_name, in_ifname) == 0) && (family == in_family)) {
      s = getnameinfo(i->ifa_addr,
		      (family == AF_INET) ? sizeof(struct sockaddr_in) : sizeof(struct sockaddr_in6),
		      out_ipaddr, in_length, NULL, 0, NI_NUMERICHOST);
      if (s != 0) {
	LOG_ERROR("getnameinfo() ... failed with [%s]", strerror(errno));
	freeifaddrs(ifaddr);
	return SSE_E_GENERIC;
      }
      break;
    }
  }
  freeifaddrs(ifaddr);
  return SSE_E_OK;
}